Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey ...
i used this code to compile a source in run time.
C#
 Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider();
 System.CodeDom.Compiler.CompilerParameters cp = new System.CodeDom.Compiler.CompilerParameters();

cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("AxInterop.MSTSCLib.dll");
cp.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
cp.ReferencedAssemblies.Add("Interop.MSTSCLib.dll");
cp.GenerateInMemory = false;
cp.GenerateExecutable = true;
cp.OutputAssembly = "chilProgram.exe";
System.CodeDom.Compiler.CompilerResults cr = cscp.CompileAssemblyFromSource(cp,"SomeCodeToCompile");


everything is good , but when i run the child program it will give me this error for activex control named "Interop.MSTSCLib.dll" :
HTML
Unhandled exception : System.BadImageFormatException : Could not load file or assembly 'Interop.MSTSCLIP, Version=1.0.0.0 ,Culture neutral, PublicKeyToken=null' or one of dependencies. An attempt was made to load a program with an incorrect format.


what is the problem? is it possible problem be about PublicKeyToken=null? or adding a activex control to references has another way?
<edit> i have new error i cant invoke any property in the dll
very thanks!
Posted
Updated 22-Apr-13 13:21pm
v2

1 solution

Hello,

BadImageFormatException usually means 64 vs 32 bit conflict. Check whether all of the assemblies are set to a particular format. This error can also occurr if you're calling a COM or a DLL which is compiled for different platform, for example you call 32 bit COM/DLL from an assembly on a 64 bit system where assembly's platform would default to x64.

Regards,
 
Share this answer
 
Comments
ali_heidari_ 22-Apr-13 15:23pm    
thanks.. im using COM ... but it work good on my windows program! when wanna make a console program in runtime which need this com and when i add this reference to my childprogram! it gives me this error ... i dnt think this error caused by platform ! can you help me?
Prasad Khandekar 22-Apr-13 15:32pm    
There are other reasons as well. Please go though this article (http://msdn.microsoft.com/en-us/library/system.badimageformatexception(v=vs.110).aspx).
ali_heidari_ 22-Apr-13 15:58pm    
very useful ... thanks a lot!
ali_heidari_ 22-Apr-13 18:53pm    
you are right! it was about platforms! well i changed target platform to AnyCPU ! know i have this error : Property set of 'UserName' cannot be invoked at this time. UserName is one of the Interop.MSTSCLib.dll properties! so whats problem now? very thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900