c++ cli - How can I call a mixed-mode C++/CLI assembly from C#? -
i've written mixed-mode c++/cli assembly, wraps native c++ library. compiles successfully. can write c++/cli application uses assembly, know works.
so wrote c# app uses same c++/cli assembly. compiles fine. when try run it, "badimageformatexception," detailed exception message below.
i think exception happening because assembly mixed-mode , therefore "unsafe." i've read, unsafe assemblies supposed trusted when run local harddrive, i'm doing.
can me understand what's going on here? i'm trying possible?
detailed exception message:
system.badimageformatexception unhandled message="could not load file or assembly 'asillyclass, version=1.0.3988.20325, culture=neutral, publickeytoken=null' or 1 of dependencies. attempt made load program incorrect format." source="consoleapplication1" filename="asillyclass, version=1.0.3988.20325, culture=neutral, publickeytoken=null" fusionlog="=== pre-bind state information === : user = sig\\user : displayname = asillyclass, version=1.0.3988.20325, culture=neutral, publickeytoken=null\n (fully-specified) : appbase = file:///c:/projects/api/testapp-c#/consoleapplication1/bin/debug/ : initial privatepath = null assembly : consoleapplication1, version=1.0.0.0, culture=neutral, publickeytoken=null. === : bind starts in default load context. : using application configuration file: c:\\projects\\api\\testapp-c#\\consoleapplication1\\bin\\debug\\consoleapplication1.vshost.exe.config : using machine configuration file c:\\windows\\microsoft.net\\framework64\\v2.0.50727\\config\\machine.config. : policy not being applied reference @ time (private, custom, partial, or location-based assembly bind). : attempting download of new url file:///c:/projects/api/testapp-c#/consoleapplication1/bin/debug/asillyclass.dll. : failed complete setup of assembly (hr = 0x8007000b). probing terminated. " stacktrace: @ consoleapplication1.program.main(string[] args) @ system.appdomain._nexecuteassembly(assembly assembly, string[] args) @ microsoft.visualstudio.hostingprocess.hostproc.runusersassembly() @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.threading.threadhelper.threadstart() innerexception:
the cause you're running 64-bit os, , there's 32/64-bit mismatch (e.g., dll 32-bit , app 64-bit/anycpu).
to fix, go app's properties , select x86 instead of anycpu.
Comments
Post a Comment