AppDomain.Load MixedMode (MC++) Dll Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    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.FileL oadException: Ausnahme von HRESULT: 0x80131019.
    at System.Reflecti on.Assembly.nLo adImage(Byte[] rawAssembly, Byte[]
    rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark)
    at System.AppDomai n.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 LoadAssemblyOnl y(string Path)
    {
    FileStream f1 = new FileStream(Path ,FileMode.Open) ;
    Byte[] rawAssemblyByte s1 = new Byte[f1.Length];
    f1.Read(rawAsse mblyBytes1,0,(i nt)f1.Length);
    f1.Close();

    AppDomain.Curre ntDomain.Assemb lyResolve +=new
    ResolveEventHan dler(CurrentDom ain_AssemblyRes olve0);
    Assembly ass = AppDomain.Curre ntDomain.Load(r awAssemblyBytes 1);
    MessageBox.Show (ass.FullName," Loaded AssemblyName");
    string AssList="";
    foreach (Assembly a in AppDomain.Curre ntDomain.GetAss emblies() )
    {
    AssList += a.FullName +"\r\n";
    }
    MessageBox.Show (AssList,"Assem blyList");
    string typelist="";
    foreach(Type t in ass.GetTypes() )
    {
    typelist += t.FullName +"\r\n";
    }
    MessageBox.Show (typelist,"Type LIst");
    }

    private Assembly CurrentDomain_A ssemblyResolve0 (object sender,
    ResolveEventArg s args)
    {
    MessageBox.Show ("Name:"+args.N ame,"ResolveEve nt") ;
    Assembly ass = Assembly.LoadFr om(args.Name);
    if(ass!=null)
    {
    MessageBox.Show ("Assembly loaded:"+ass.Fu llName);
    }
    else
    {
    MessageBox.Show ("Assembly not loaded");
    }
    return ass;
    }
    ////////////////////////

    Best regards in advance
    John


  • Junfeng Zhang[MSFT]

    #2
    Re: AppDomain.Load MixedMode (MC++) Dll Problem

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

    --
    Junfeng Zhang


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

    "John" <paradisaea@gmx .de> wrote in message
    news:uGOnkKqHFH A.1176@TK2MSFTN GP12.phx.gbl...[color=blue]
    > 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.FileL oadException: Ausnahme von HRESULT: 0x80131019.
    > at System.Reflecti on.Assembly.nLo adImage(Byte[] rawAssembly, Byte[]
    > rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark)
    > at System.AppDomai n.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 LoadAssemblyOnl y(string Path)
    > {
    > FileStream f1 = new FileStream(Path ,FileMode.Open) ;
    > Byte[] rawAssemblyByte s1 = new Byte[f1.Length];
    > f1.Read(rawAsse mblyBytes1,0,(i nt)f1.Length);
    > f1.Close();
    >
    > AppDomain.Curre ntDomain.Assemb lyResolve +=new
    > ResolveEventHan dler(CurrentDom ain_AssemblyRes olve0);
    > Assembly ass = AppDomain.Curre ntDomain.Load(r awAssemblyBytes 1);
    > MessageBox.Show (ass.FullName," Loaded AssemblyName");
    > string AssList="";
    > foreach (Assembly a in AppDomain.Curre ntDomain.GetAss emblies() )
    > {
    > AssList += a.FullName +"\r\n";
    > }
    > MessageBox.Show (AssList,"Assem blyList");
    > string typelist="";
    > foreach(Type t in ass.GetTypes() )
    > {
    > typelist += t.FullName +"\r\n";
    > }
    > MessageBox.Show (typelist,"Type LIst");
    > }
    >
    > private Assembly CurrentDomain_A ssemblyResolve0 (object sender,
    > ResolveEventArg s args)
    > {
    > MessageBox.Show ("Name:"+args.N ame,"ResolveEve nt") ;
    > Assembly ass = Assembly.LoadFr om(args.Name);
    > if(ass!=null)
    > {
    > MessageBox.Show ("Assembly loaded:"+ass.Fu llName);
    > }
    > else
    > {
    > MessageBox.Show ("Assembly not loaded");
    > }
    > return ass;
    > }
    > ////////////////////////
    >
    > Best regards in advance
    > John
    >
    >[/color]


    Comment

    Working...