Skip to content

Commit f48cd06

Browse files
committed
CLJCLR-198: Fix some issues with initializaing ClojureCLR when running in a CLR runtime hosted in a non-managed app.
1 parent 862db8e commit f48cd06

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

Clojure/Clojure/Lib/RT.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,17 @@ static RT()
428428
ScriptRuntime env = new(setup);
429429
env.GetEngine("clj");
430430

431+
// Having a problem locating the Clojure.resources.dll (dynamically generated) when running with CLR hosted in a non-managed app (such as a C++ app),
432+
// so I'm going to try loading it here, and if it fails, we'll just hope the resources are available on the standard file search path.
431433

432-
_versionProperties.LoadFromString(clojure.lang.Properties.Resources.version);
434+
try
435+
{
436+
_versionProperties.LoadFromString(clojure.lang.Properties.Resources.version);
437+
}
438+
catch
439+
{
440+
_versionProperties.LoadFromString("0.0.0");
441+
}
433442

434443
Keyword arglistskw = Keyword.intern(null, "arglists");
435444
Symbol namesym = Symbol.intern("name");
@@ -466,7 +475,14 @@ static RT()
466475
// If not found, we hope that the source files core.clj, etc. are available on the standard file search path
467476

468477

469-
string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
478+
// Apparently this can cause a problem when the CLR is embedded in a non-managed app (such as a C++ app)
479+
// -- it will be an empty string and then we end up with a relative instead of an absolute path,
480+
// which will cause Assembly.LoadFile to throw an ArgumentException.
481+
//string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
482+
483+
// THis alternative is supposed to work.
484+
string baseDir = Path.GetDirectoryName(typeof(RT).Assembly.Location);
485+
470486

471487
try
472488
{
@@ -480,6 +496,11 @@ static RT()
480496
{
481497
// this is okay. It just means that the assets clojure/core.clj and company are going to be somewhere else
482498
}
499+
catch (ArgumentException)
500+
{
501+
// This can happen when using CLR embedded in a non-managed app (such as C++ app)
502+
503+
}
483504

484505
// Moved the intiailization of *compiler-options* from the clojure.lang.Compiler static constructor to here.
485506
// We need to make sure direct linking is turned on for this load (and later on for the load of the spec files)

0 commit comments

Comments
 (0)