Connecting Tech Pros Worldwide Help | Site Map

CLR Runtime not finding an assembly even though it is loaded and running

Newbie
 
Join Date: Nov 2008
Posts: 1
#1: Nov 17 '08
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:

Expand|Select|Wrap|Line Numbers
  1. ICLRRuntimeHost*        Clr = NULL;
  2. HMODULE                 hMsCorEE = LoadLibraryA("mscoree.dll");
  3. PROC_CorBindToRuntime*  CorBindToRuntime = (PROC_CorBindToRuntime*)GetProcAddress(hMsCorEE, "CorBindToRuntime");
  4.  
  5. CorBindToRuntime(NULL, NULL, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void**)&Clr));
  6.  
  7. ClrHost->Start();
  8.  
  9. Clr->ExecuteInDefaultAppDomain("MyLib", L"MyNamespace.MyClass", L"MyMethod", MyParams, &RetVal);
  10.  
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:
Expand|Select|Wrap|Line Numbers
  1.             Assembly SampleAssembly;
  2.             Int32 Integer1 = new Int32();
  3.             Type Type1;
  4.            SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
  5.             file.WriteLine("FullName=" + SampleAssembly.FullName);
  6.  
Output:

FullName=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

CODE:
Expand|Select|Wrap|Line Numbers
  1.             Type t = typeof(System.Data.DataSet);
  2.             file.WriteLine("FullNameAgain=" + t.Assembly.FullName.ToString());
  3.  
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
Reply


Similar .NET Framework bytes