I have a scenario in which I am adding DLLs to the GAC from actions in my C# code. I then need to do an Assembly.Load on the newly added DLL. However, since the DLL wasn’t in the GAC when the process started, it returns null.
So, I see that code can be run in a different AppDomain, which would result in the DLL being available from the GAC in the separate AppDomain.
How can I return the value from the other AppDomain to my main thread?
I simply want to run:
var type = Assembly.Load(assembly).GetType(className);
And have it return from the other AppDomain to my main thread.
You’ll have to play a little with .NET Remoting. Your objects loaded on the other AppDomain will need to derive from the MarshalByRefObject class (http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject.aspx).
Just to save time, here’s the code from that link: