OS: Windows XP (32 bit)
NET: .Net 2.0 runtime
DevEnv: VS 2008 C++ and C#
I am attempting to use an unmanaged C++ library to load a managed C# assembly and hand off control. I have the following in my C++ routine:
- ICLRRuntimeHost* Clr = NULL;
-
HMODULE hMsCorEE = LoadLibraryA("mscoree.dll");
-
PROC_CorBindToRuntime* CorBindToRuntime = (PROC_CorBindToRuntime*)GetProcAddress(hMsCorEE, "CorBindToRuntime");
-
-
CorBindToRuntime(NULL, NULL, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void**)&Clr));
-
-
ClrHost->Start();
-
-
Clr->ExecuteInDefaultAppDomain("MyLib", L"MyNamespace.MyClass", L"MyMethod", MyParams, &RetVal);
-
This code is actually working in that the library is being loaded and my class.method is executed. However in my method there is code that is attempting to de-serialize some of the data being passed in as the parameter string which is throwing an exception as follows:
System.Runtime.Serialization.SerializationExceptio n: Unable to find assembly 'MyLib, Version=2.5.0.5, Culture=neutral, PublicKeyToken=4b580fca19d0b0c5'.
Even though the code that was executing at the time of the exception was the very library that is not being found.
I did some testing to determine what the runtime believes the full name of the currently executing assembly to be and I got the following depending on the method I used to retrieve it:
CODE:
- Assembly SampleAssembly;
-
Int32 Integer1 = new Int32();
-
Type Type1;
-
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
-
file.WriteLine("FullName=" + SampleAssembly.FullName);
-
Output:
FullName=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
CODE:
- Type t = typeof(System.Data.DataSet);
-
file.WriteLine("FullNameAgain=" + t.Assembly.FullName.ToString());
-
Output:
FullName=System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
I have seen sparse reference to potential complications resulting from the method CLR uses to locate assemblies, but nothing is clear as to how I can overcome this, other then having MyLib registered in the GAC which does bypass the problem. However, I am trying to eliminate the need to manage the code in the GAC. It would seem that I am missing something since I am able to load and run the managed code, but the library name is not being loaded with the assembly (or at least not correctly)...
Any ideas would be appreciated.
Thanks.
creo