❔ Confused about Assembly.Load (Hotloading CSharp Assemblies)
I want to be able to load/unload user made C# libraries during runtime. However, these user libraries rely on one C# FunctionLibrary.dll file I made that will basically hold functions that call Native C++ functions.
FunctionLibrary.dll is structured like this:
UserLibrary.dll is structured like this:
FunctionLibrary.dll
and UserLibrary.dll
are loaded using Assembly.Load
, which looks something like this:
Invoking MyLibrary.OnStartup
prints false
, not true
. I assume I'm just going the wrong way about this, but I'm not really sure how to achieve my goal. I appreciate any help I can get on understanding what I'm doing wrong.5 Replies
It might be better to use a common interface for your modules instead of a static class, my guess would be the module is referencing a different instance of the library
Hmm alright. Is it possible to only have one instance of FunctionLibrary.dll and have everything reference that same instance?
what is the value when you call testField.GetValue(null)?
after doing a short amount of research, it appears the libraries have to be loaded under the same appdomain to properly share the static class
what are you trying to make exactly?
Well what I'm doing is using the HostFXR API to host a C# runtime so I can interop with C++ functions. I've changed the project to output to a .exe just for testing purposes, and it prints out the expected result of "True".
However, when I switch the project back to "Class Library" and try to load the library with HostFXR, it prints out this error:
I've also modified the host's code to look like this:
Which again, works if I just compile the host as a .exe and run it on it's own. But it does not work if I try compiling it as a .dll and loading it with HostFXR, it produces the error above.
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.