Home All Groups Group Topic Archive Search About

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

Author
30 Sep 2005 11:53 AM
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
Author
30 Sep 2005 3:03 PM
Willy Denoyette [MVP]
LoadFrom is for managed assemblies only. Unmanaged DLL's and EXE's cannot be
loaded by this function.

Willy.

Show quoteHide quote
"Tarandeep Singh" <tarand***@abosoftware.com> wrote in message
news:%23nnbuXbxFHA.2848@TK2MSFTNGP15.phx.gbl...
> 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
>
>
Are all your drivers up to date? click for free checkup

Author
28 Oct 2005 6:26 PM
Werner Schaudin
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



"Willy Denoyette [MVP]" schrieb:

Show quoteHide quote
> LoadFrom is for managed assemblies only. Unmanaged DLL's and EXE's cannot be
> loaded by this function.
>
> Willy.
>
> "Tarandeep Singh" <tarand***@abosoftware.com> wrote in message
> news:%23nnbuXbxFHA.2848@TK2MSFTNGP15.phx.gbl...
> > 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
> >
> >
>
>
>
Author
14 Nov 2005 10:03 AM
Allan BB
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


Show quoteHide quote
"Werner Schaudin" wrote:

> 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."
Author
14 Nov 2005 10:28 AM
Richard Grimes
Allan BB wrote:
> 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/default.asp?url=/library/en-us/vcmex/html/vclrfproducingverifiablecomponentswithmanagedc.asp

Richard
Author
14 Nov 2005 11:47 AM
Allan BB
"Richard Grimes" wrote:
> If you use VS2005 its easy, use /clr:pure <g>
>
> If you use VS2003, you have to jump through hoops,
....
> The full details are here:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vclrfproducingverifiablecomponentswithmanagedc.asp
>

Thanks for the (too) speedy reply Richard. I've just posted a more detailed
query on the subject (specifically: why doesn't it work for exe's?), before
seeing your reply here.

Allan
Author
14 Nov 2005 7:20 PM
Werner Schaudin
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



"Allan BB" schrieb:

Show quoteHide quote
> "Richard Grimes" wrote:
> > If you use VS2005 its easy, use /clr:pure <g>
> >
> > If you use VS2003, you have to jump through hoops,
> ...
> > The full details are here:
> >
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vclrfproducingverifiablecomponentswithmanagedc.asp
> >
>
> Thanks for the (too) speedy reply Richard. I've just posted a more detailed
> query on the subject (specifically: why doesn't it work for exe's?), before
> seeing your reply here.
>
> Allan
>

Bookmark and Share