473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 2414
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Satinderpal Singh | last post by:
Hi All, I have an EXE, I load the DLL from that exe in a seperate AppDomain. (I have not given reference to that DLL from the EXE). Now, i call some commands of that dll from the EXE, and in...
4
by: Mirano | last post by:
Hi everybody. I load an assembly into another AppDomain, not a default one. As there is no way to unload the assembly, I need to unload the domain. This is where the app hangs. The problem is...
2
by: Lauren Hines | last post by:
Hello, I have read numerous post stating that the only way to unload an assembly (DLL in my case) is to create a separate AppDomain, load the assembly, then unload it by calling AppDomain.Unload....
8
by: A. Elamiri | last post by:
Hello, I created a small app which acts as a services manager. I basically drop a DLL in a Services folder and set the frequency through the application for how often do I want the code in the...
6
by: Wal Turner | last post by:
Hi there. There are various snippets on forums regarding issues with AppDomain.Unload and how it just doesnt work. Fortunately, I got it working with the base case, after much fiddling. Consider...
5
by: F. Prefect | last post by:
Hello, (sorry for reposting this.) We are having the following scenario: A ASP.NET Application (C#) is using a managed C++ assembly, which is a thin wrapper around an old C++ lib. (We are...
3
by: Frank Uray | last post by:
Hi all I have a problem with loading a assembly ... I am trying to do the following: - I have a directory with a dll (assembly) in it (not the currect dir.) - I am trying to load this assembly,...
4
by: illegal.prime | last post by:
Hi all, I'm getting unexpected results when trying to preload assemblies into an AppDomain I'm creating. Upon creation of the AppDomain - I attach an AssemblyResolve to both my current AppDomain...
1
anfetienne
by: anfetienne | last post by:
i have this code below that i made....it loads vars from txt file splits it then puts it into an array....once in an array it the brings the pics in from the array to create thumbnails and a larger...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.