468,268 Members | 1,656 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

AppDomain.Load MixedMode (MC++) Dll Problem

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
Nov 17 '05 #1
1 2138
It is not possible to load MC++ assembly through Assembly.Load(byte[]). MC++
assembly requires fixup which cannot be performed in byte array.

--
Junfeng Zhang
http://blogs.msdn.com/junfeng

This posting is provided "AS IS" with no warranties, and confers no rights.

"John" <pa********@gmx.de> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
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

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Satinderpal Singh | last post: by
4 posts views Thread by Mirano | last post: by
2 posts views Thread by Lauren Hines | last post: by
8 posts views Thread by A. Elamiri | last post: by
6 posts views Thread by Wal Turner | last post: by
3 posts views Thread by Frank Uray | last post: by
4 posts views Thread by illegal.prime | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.