From: Jonathan Gilbert on 10 Feb 2010 16:20 Hello, I work for a company that sells .NET software and have recently been tasked with handling support issues to do with our update system, which I wrote. Since the updater is the first thing that runs when the desktop icon is clicked, I also get unrelated issues, and one that has been coming up repeatedly is the following exception while trying to instantiate an XmlSerializer: System.TypeInitializationException: The type initializer for 'IQ.Core.UpdateFoundation.Dispatcher.DispatchRequest' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly '0 bytes loaded from System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: '0 bytes loaded from System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.BadImageFormatException: Bad IL format. at System.Reflection.Assembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection) at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence securityEvidence) at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames) at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources) at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources) at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources) at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence) at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies) at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence) at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace, String location, Evidence evidence) at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace, String location, Evidence evidence) at System.Xml.Serialization.XmlSerializer..ctor(Type type, Type[] extraTypes) at IQ.Core.UpdateFoundation.Dispatcher.DispatchRequest..cctor() In attempting to debug this issue, I wrote, on the client's machine, a tiny test application whose only statement was the creation of an XmlSerializer, and when I attempted to compile it using the C# compiler installed on the client machine as part of the .NET Framework, I found that CSC.EXE produces no output at all: C:\testxml>csc test.cs C:\testxml>csc /? C:\testxml>csc C:\testxml> I rooted around to try to find the cause, and one of the other things I tried was running WCF's ServiceModelReg utility, and that produced similar output, receiving an error from somewhere within the framework: C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>ServiceModelReg.exe /i Microsoft(R) Windows Communication Foundation Installation Utility [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.4037] Copyright (c) Microsoft Corporation. All rights reserved. Error: Could not load file or assembly '0 bytes loaded from System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An attempt was made to load a program with an incorrect format. C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation> I have tried uninstalling and reinstalling .NET, using both .NET's own uninstaller and the removal tool that Aaron Stebner put on his blog, but to no avail. The above symptoms persist with no change. Has anybody seen this before or know what the problem is? So far, we have only succeeded in solving the problem on a single client workstation, and the "solution" was a complete reinstallation of Windows. Thanks, Jonathan
From: Jeroen Mostert on 11 Feb 2010 10:58 On 2010-02-10 22:20, Jonathan Gilbert wrote: > I work for a company that sells .NET software and have recently been > tasked with handling support issues to do with our update system, > which I wrote. Since the updater is the first thing that runs when the > desktop icon is clicked, I also get unrelated issues, and one that has > been coming up repeatedly is the following exception while trying to > instantiate an XmlSerializer: > > System.TypeInitializationException: The type initializer for > 'IQ.Core.UpdateFoundation.Dispatcher.DispatchRequest' threw an > exception. ---> System.BadImageFormatException: Could not load file or > assembly '0 bytes loaded from System, Version=2.0.0.0, > Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its > dependencies. An attempt was made to load a program with an incorrect > format. http://support.microsoft.com/kb/919825 is not your scenario, but it might have the same root cause (an invalid assembly generating a misleading error message). The trouble is figuring out which assembly. Try using procmon (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) to identify the failing assembly as it's being loaded. You can use peverify.exe to check if it's valid. It might be your own assembly, being corrupted as it's downloaded. However, if a complete reinstall of the .NET Framework doesn't help and it also affects .NET software other than your own, this suggests no single assembly is the problem. Reboot into safe mode and see if the problem still occurs. File-system filter drivers like the ones installed by antivirus programs can prevent successful file access. Process Monitor should be able to see this as well, though it may not be as obvious. -- J.
From: Jonathan Gilbert on 11 Feb 2010 12:44 On Feb 11, 9:58 am, Jeroen Mostert <jmost...(a)xs4all.nl> wrote: > On 2010-02-10 22:20, Jonathan Gilbert wrote: > > > I work for a company that sells .NET software and have recently been > > tasked with handling support issues to do with our updatesystem, > > which I wrote. Since the updater is the first thing that runs when the > > desktop icon is clicked, I also get unrelated issues, and one that has > > been coming up repeatedly is the following exception while trying to > > instantiate an XmlSerializer: > > >System.TypeInitializationException: The type initializer for > > 'IQ.Core.UpdateFoundation.Dispatcher.DispatchRequest' threw an > > exception. ---> System.BadImageFormatException: Could not load file or > > assembly '0bytesloadedfromSystem, Version=2.0.0.0, > > Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its > > dependencies. An attempt was made to load a program with an incorrect > > format. > > http://support.microsoft.com/kb/919825is not your scenario, but it might > have the same root cause (an invalid assembly generating a misleading error > message). The trouble is figuring out which assembly. Try using procmon > (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) to identify > the failing assembly as it's beingloaded. You can use peverify.exe to check > if it's valid. It might be your own assembly, being corrupted as it's > downloaded. > > However, if a complete reinstall of the .NET Framework doesn't help and it > also affects .NET software other than your own, this suggests no single > assembly is the problem. Reboot into safe mode and see if the problem still > occurs. File-systemfilter drivers like the ones installed by antivirus > programs can prevent successful file access. Process Monitor should be able > to see this as well, though it may not be as obvious. > > -- > J. Thanks for this information. With it, and armed with the stack trace in the original post, I wrote a simple test app: CodeDomProvider provider = CodeDomProvider.CreateProvider("C#"); CompilerResults results = provider.CompileAssemblyFromSource( new CompilerParameters() { GenerateExecutable = true, GenerateInMemory = false, IncludeDebugInformation = false, OutputAssembly = "Test", }, @"using System; class Test { static void Main() { Console.WriteLine(""It worked!""); } }"); This returns without errors, but as soon as I access the CompiledAssembly property of the CompilerResults object, I immediately get: System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Tes tApp\Test' or one of its dependencies. The system cannot find the file specified .. File name: 'file:///C:\TestApp\Test' at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity) at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly() This brings things into clarity; the error is that CSC is not working, and the "0 bytes loaded from System", in which the filename is wrong, is merely a symptom of this. I will follow up if/when I discover why CSC isn't working. Thanks for your suggestions. Disabling anti-virus software and running in safe mode will be the first things I try next. Jonathan
From: Jonathan Gilbert on 12 Feb 2010 16:08 On Feb 11, 11:44 am, Jonathan Gilbert <logic...(a)gmail.com> wrote: [..] > This brings things into clarity; the error is that CSC is not working, > and the "0 bytes loaded from System", in which the filename is wrong, > is merely a symptom of this. > > I will follow up if/when I discover why CSC isn't working. > > Thanks for your suggestions. Disabling anti-virus software and running > in safe mode will be the first things I try next. I investigated installed anti-virus software on the machine and discovered that it had "Additional Guard" installed -- a fake anti- spyware program that is itself malware. It had added a program compatibility entry in the registry with the effect of preventing any program named CSC.EXE from running (along with ~700 others). After running Malwarebytes' Anti-Malware, which removed all of these, CSC.EXE began working again, and the related errors in calls into CodeDom (and XmlSerializer, which uses CodeDom) went away. The machine is once again working properly. Thanks for your help, Jonathan
|
Pages: 1 Prev: File associations in .Net framework library Next: Windows 7 64 bit and IO.Ports.SerialPort |