Click here to Skip to main content
13,050,840 members (72,104 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hey ...
i used this code to compile a source in run time.
 Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider();
 System.CodeDom.Compiler.CompilerParameters cp = new System.CodeDom.Compiler.CompilerParameters();
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" :
Unhandled exception : System.BadImageFormatException : Could not load file or assembly 'Interop.MSTSCLIP, Version= ,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 22-Apr-13 8:08am
Updated 22-Apr-13 13:21pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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.

source.compiler 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 (
source.compiler 22-Apr-13 15:58pm
very useful ... thanks a lot!
source.compiler 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100