AppDomain.Load MixedMode (MC++) Dll Problem

J

John

Hi,

I tried to load a mixedmode dll (MC++) with AppDomain.Load(Byte[] ) in a C#
Client.
During the Load Process I got the following Exception:

System.IO.FileLoadException: Ausnahme von HRESULT: 0x80131019.
at System.Reflection.Assembly.nLoadImage(Byte[] rawAssembly, Byte[]
rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark)
at System.AppDomain.Load(Byte[] rawAssembly) ...

I also tried this with a pure managed MC++ dll and got the same error.

If I load a normal C# dll everythink is fine.

Here's the code loading the Assembly:


Any Suggestions?

////////////////////////Code Snippet for Loading the Assembly

public void LoadAssemblyOnly(string Path)
{
FileStream f1 = new FileStream(Path ,FileMode.Open);
Byte[] rawAssemblyBytes1 = new Byte[f1.Length];
f1.Read(rawAssemblyBytes1,0,(int)f1.Length);
f1.Close();

AppDomain.CurrentDomain.AssemblyResolve +=new
ResolveEventHandler(CurrentDomain_AssemblyResolve0);
Assembly ass = AppDomain.CurrentDomain.Load(rawAssemblyBytes1);
MessageBox.Show (ass.FullName,"Loaded AssemblyName");
string AssList="";
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies() )
{
AssList += a.FullName +"\r\n";
}
MessageBox.Show(AssList,"AssemblyList");
string typelist="";
foreach(Type t in ass.GetTypes() )
{
typelist += t.FullName +"\r\n";
}
MessageBox.Show(typelist,"TypeLIst");
}

private Assembly CurrentDomain_AssemblyResolve0(object sender,
ResolveEventArgs args)
{
MessageBox.Show ("Name:"+args.Name,"ResolveEvent") ;
Assembly ass = Assembly.LoadFrom(args.Name);
if(ass!=null)
{
MessageBox.Show ("Assembly loaded:"+ass.FullName);
}
else
{
MessageBox.Show ("Assembly not loaded");
}
return ass;
}
////////////////////////

Best regards in advance
John
 
J

Junfeng Zhang[MSFT]

It is not possible to load MC++ assembly through Assembly.Load(byte[]). MC++
assembly requires fixup which cannot be performed in byte array.
 
P

Philippe PUAUD

"It is not possible to load MC++ assembly through Assembly.Load(byte[]).
MC++
assembly requires fixup which cannot be performed in byte array."

partially true :
Imports fixups cannot be performed in byte array.

If your MC++ dll imports only _CorDllMain (from mscoree.dll)
It can be loaded from byte array in v1.1;
BUG:v2.0 loads only pureIL assemblies from byte array (regression comparing
to v1.1)

If you are not convinced, I can post you a simple solution that loads
something unmanaged from byte array (in v1.1 but not in v2.0)

Best regards,
Philippe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top