why Assembly.LoadFrom() function does'nt load VC++ Project exe file

  • Thread starter Thread starter Tarandeep Singh
  • Start date Start date
T

Tarandeep Singh

Hello all
I am facing one problem while loading VC++ EXe file through
Assembly.LoadFrom() Function,
It gives Error -
The format of the file 'totest.exe'(VC++) is invalid
please give me solution for it
 
LoadFrom is for managed assemblies only. Unmanaged DLL's and EXE's cannot be
loaded by this function.

Willy.
 
Dear Willy,

"Assembly::LoadFrom(<managed C++ assembly>.exe)"
does not work if the .Net assemblies (EXE, DLL) is created with managed C++.

There comes an exception with the following error message:
"Unverifiable image 'DotNetCPPAppl2.exe' can not be run."

"LoadFrom" works if the assembly is created with e.g. C# or VB but it is not
working for managed C++ assemblies.

My environment:
.Net Framework 1.1
Visual Studio 2003
Managed C++ .Net Project/Application
2 Sample application using "LoadFrom": One ceated with C#
One created with
managed C++

Any help would to find a solution for this problem would be great.

Regards,
Werner Schaudin
Schaudin.com, Germany
 
I think the error message says it all: the assembly built with (managed
extensions for) C++ is unverifiable. The question is, how do you build a
verifiable .exe assembly using C++ (whether or not you want to use
LoadFrom()). If someone has the answer, I too would be truly grateful.

Cheers,

Allan
 
Allan said:
I think the error message says it all: the assembly built with
(managed extensions for) C++ is unverifiable. The question is, how do
you build a verifiable .exe assembly using C++ (whether or not you
want to use LoadFrom()). If someone has the answer, I too would be
truly grateful.

If you use VS2005 its easy, use /clr:pure <g>

If you use VS2003, you have to jump through hoops, and it won't
necessarily work. First, you have to get rid of the CRT (and hence no
global variables), next you have to get rid of all unmanaged types.
Replace static_cast<>'s and reinterpret_cast<>'s.

The odd thing is that you have to define a global variable called
_fltused and a global function called
_check_commonlanguageruntime_version. You also have to compile with
/clr:initialAppDomain, which is odd, because this is the v1.0 behaviour
(and has problems). Finally, you have to run SetILOnly on the assembly.

The full details are here:

http://msdn.microsoft.com/library/d...producingverifiablecomponentswithmanagedc.asp

Richard
 
Hello,

any changes to the build is no help for me because we handle with EXE files
not created from us. We want to load EXE files from other so software
vendors.
We do not have the code -- only the EXE file.

I still think to know why a managed C++ assembly cannot be loaded with
"LoadFrom":

The reason is a C++ managed EXE is loaded (using "LoadFrom") to a fixed
address
(start entry point) into the memory. Because this address is already used by
the calling (running) program (my program which calles "LoadFrom") the C++
EXE module is not loaded. A mangaged C++ DLL can be loaded because a DLL
does not have a fixed loading address.


Werner Schaudin
www.schaudin.com
 
Back
Top