locked
load a non .net dll into an application domain RRS feed

  • Question

  • Hi All,

     

    I am trying to load and run a non .net dll (a fortran dll named f.dll) in a separate application domain in my c # code. Here is the code:

     

    void main (){
      AppDomain chmDomain = AppDomain.CreateDomain("fDomain");          
                
     int result =fDomain.ExecuteAssembly(pathtofdll);
               
     AppDomain.Unload(fDomain);
    }
    

    And I am getting the error in executeassembly method:

    BadImageFormatException , .....file ...f.dll  The module was expected to contain an assembly manifest.

     

    My question is:

    can executeassembly load and run a non .net assembly? If not, what is the correct way to load and run a fortran dll into a separate application domain?

    I am able to load and run it into the current domain using P/Invoke. Thanks for the time!

     

    Boyu

    Friday, February 11, 2011 5:29 PM

Answers

  • AppDomain's only know about and work with .NET assemblies.

    You'll need to make an assembly that loads the DLL via P/Invoke.  Once you have that, you can use your code above to load that (.NET) assembly, and it will execute your fortran code.

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Boyu Zhang Friday, February 11, 2011 5:57 PM
    Friday, February 11, 2011 5:41 PM
    Moderator