I've read as many different version of this question as are on Stack Overflow, as well as every blue link on the front page of 3 different Google searches for tutorials, as well as the MSDN (which is kind of shallow beyond executing assemblies). I can only think of my efforts to get Tao to work as a good test case, but believe me, I've tried with a simple string return, a double, a function with parameters, too. Whatever my problem is, it isn't Tao.
Basically I want to create a testLibraryDomain.CreateInstance()
of my Draw class in the GLPlugin namespace.
if( usePlugin )
{
AppDomain testLibraryDomain = AppDomain.CreateDomain( "TestGLDomain2" );
//What the heck goes here so that I can simply call
//the default constructor and maybe a function or two?
AppDomain.Unload( testLibraryDomain );
}
Gl.glBegin( Gl.GL_TRIANGLES );
I know for a fact that:
namespace GLPlugin
{
public class DrawingControl : MarshalByRefObject
{
public DrawingControl()
{
Gl.glColor3f( 1.0f , 0.0f , 0.0f );
//this is a test to make sure it passes
//to the GL Rendering context... success
}
}
}
indeed changes the pen color. It works when I give it a static void Main( string args[] )
entry point and I call testLibraryDomain.ExecuteAssembly( thePluginFilePath )
Whether or not a direct ExecuteAssembly would work had concerned me, as I was not certain the GL Calls would make it into the "top level" AppDomain's OpenGL context. It even lets me overwrite the assembly and change the Pen Color a second time. Unfortunately giving it an executable entry point means that a popup console interrupts me then goes away. It also works when I simply give it a reference in the Project and create a regular GLPlugin.DrawingTool tool = new GLPlugin.DrawingControl()
, or even creating a someAssembly = Assembly.LoadFrom( thePluginFilePath )
(which of course and unfortunately, locks the assembly, preventing replacement/recompilation).
When using any of the various methods I've tried, I always get "the given assembly name or its code base is invalid." I promise, it is valid. Something in the way I'm trying to load it is not.
One thing I know I'm lacking is a correct setup for the testLibraryDomain.CreateInstance( string assemblyName , string typeName);
As far as I can tell, the assemblyName argument is not the filepath to the assembly file. Is it the namespace, or even just the assembly name, ie: GLPlugin
? If so, where do I reference the actual file? There is no someAppDomain.LoadFrom( someFilename ), though it would be dang handy if there were. Additionally, what the heck is the Type, and string typeName at that? I don't want to put in "Object"
here do I, since is not creating type other than an instance of an object? I've also tried CreateInstanceAndUnwrap( ... , ... )
with the same lack of a fundamental understanding of AppDomain. Usually I can muddle through tutorials and get things to work, even though I often don't understand the "Why?"... not so here. Usually it is helpful for me to look up six different tutorials... not so here again, but because every one takes a fundamentally (or what appears to be so) approach.
So please ELI5... I want to load an instance of a class from a dll in a separate AppDomain, maybe run a few functions, and unload it. Eventually create a list of these functions as List, removing/updating as necessary... I'd love to be able to pass arguments to them as well, but that will be step 2. According to StackOverflow, I have to learn about serializable
which I will put off for another day. (I imagine you'll be able to figure from my example what I'm trying to do.)