469,271 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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

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");
  5. CorBindToRuntime(NULL, NULL, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void**)&Clr));
  7. ClrHost->Start();
  9. 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=, 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:

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);

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

Expand|Select|Wrap|Line Numbers
  1.             Type t = typeof(System.Data.DataSet);
  2.             file.WriteLine("FullNameAgain=" + t.Assembly.FullName.ToString());

FullName=System.Data, Version=, 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.


Nov 17 '08 #1
0 1480

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Outshined | last post: by
2 posts views Thread by Mike Talbot | last post: by
1 post views Thread by Kent Rollins | last post: by
5 posts views Thread by jon morgan | last post: by
8 posts views Thread by Rick Strahl [MVP] | last post: by
7 posts views Thread by yuanlinjiang | last post: by
5 posts views Thread by Luis Arvayo | last post: by
4 posts views Thread by Per Bolmstedt | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.