Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ActiveX CodeDOM
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.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" :
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?
i have new error i cant invoke any property in the dll
very thanks!
Posted 22-Apr-13 9:08am
Edited 22-Apr-13 14:21pm
v2

1 solution

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

Solution 1

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,
  Permalink  
Comments
source.compiler at 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 at 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).
source.compiler at 22-Apr-13 15:58pm
   
very useful ... thanks a lot!
source.compiler at 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
0 OriginalGriff 250
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 DamithSL 125
4 Afzaal Ahmad Zeeshan 120
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2014
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