On 32bit Windows 7: Unable to generate a temporary class, An attempt was made to load a program with an incorrect format CS0009
Having a problem with a .NET program that runs on many machines, but is failing on one. The program is a bootstrapper that downloads the real program files from a web service.
Client received two new Windows 7 32bit machines. Program runs fine on one and fails on the other.
Error is below. (I'm retyping from screen shot, so going to skip some details in stack trace.)
There was an error when trying to start the target application: Unable to generate a temporary class (result=1). error CS0009: Metadata file 'c开发者_开发百科:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.XML.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format.' System.InvalidOperationException: Unable to generate a temporary class (result=1). error CS0009: Metadata file 'c:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.XML.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format.' at System.Xml.Serialization.Compiler.Compile... at System.Xml.Serialization.TempAssembly.GenerateAssembly... at System.Xml.Serialization.TempAssembly..ctor... at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache... at System.Xml.Serialization.XmlSerializer.FromMappings... at System.Web.Services.Protocols.SoapClientType..ctor(Type type) at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor() at [our class that inherits from SoapHttpClientProtocol]..ctor() (default ctor) at [our class that calls the service].updateApplication()
The incorrect format error seems to most typically be associated with trying to load a 32bit dll into a 64 bit process, but since this is a 32bit OS, that can't be the problem. That section of the GAC seems to be for the JIT to compile to the correct platform as needed (in this case should be 32 bit). So I really can't see anything that could be wrong here.
User has used Program Features to remove and reinstall Framework 3.5.
Any other ideas short of reimage?
Thanks, Chris
It looks like you could write only parts of your assembly to the temp folder which was generated by XmlSerializer. First it creates a C# file with the serialization code in your temp folder and compiles it there. The error message might be misleading but either you did not have write access to the temp folder for some reason or something went wrong while compiling and writing the temporary assembly to the temp folder. Usually people start pointing with their fingers to some suspect who might or might not be responsible. As Hans said the hard disc might be corrupt or a virus scanner did get in the way. Windows normally logs disc access problems in the System or Application event log where you should see disc problem from SMART monitoring. If not I would try to disable any virus scanner. If you do not have one try to install one and check for malware.
Yours, Alois Kraus
精彩评论