none
Failed to load assembly, 0 bytes from System RRS feed

  • Question

  • Hi!

    We've install .Net 4.0 Full at a client site.  Current System.dll version is 4.0.30319.236.

    Our test application opens without a problem and I initiate a simple "echo" to a WCF service on the same network.  However, I get this nasty error when the service call is invoked:

     

    Creating proxy
    calling service method
    ERROR: exception during service call and response process: Could not load file or assembly '0 bytes loaded from System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    System.BadImageFormatException
    
    Server stack trace:
       at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, SecurityContextSource securityContextSource)
       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.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
       at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
       at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GenerateSerializers()
       at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.SerializerGenerationContext.GetSerializer(Int32 handle)
       at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.MessageInfo.get_BodySerializer()
       at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, Object[] parameters, Object returnValue, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
       at System.ServiceModel.Channels.BinaryMessageEncoderFactory.BinaryMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
       at Microsoft.Samples.CompressionEncoder.MyCompressionMessageEncoderFactory.MyCompressionMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset) in C:\Projects\TariffServices\TariffService\Source\Service Interface\CompressionEncoder\MyCompressionMessageEncoderFactory.cs:line 163
       at System.ServiceModel.Channels.FramingDuplexSessionChannel.EncodeMessage(Message message)
       at System.ServiceModel.Channels.FramingDuplexSessionChannel.OnSend(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.OutputChannel.Send(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.TransactionDuplexChannelGeneric`1.Send(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at PMA_Tariff_Link.TariffClientServiceReference.ClientServiceContract.Echo(EchoRequest_Client request)
       at PMA_Tariff_Link.TariffClientServiceReference.ClientServiceContractClient.PMA_Tariff_Link.TariffClientServiceReference.ClientServiceContract.Echo(EchoRequest_Client request) in C:\Projects\TariffServices\PMA_Tariff_Link\Service References\TariffClientServiceReference\Reference.cs:line 1285
       at PMA_Tariff_Link.DataService.Echo(String message) in C:\Projects\TariffServices\PMA_Tariff_Link\DataService.cs:line 2931
    INNER ERROR: Bad IL format.
    System.BadImageFormatException
    


    We've re-installed the framework numerous times, I've tried re-ngen'ing the System.dll.  Nothing works.

    I've run the .Net setup verification tools, comes back with no errors.

    The System.dll has a size of 3 510 600 bytes.

    On the server machine (hosting the WCF service), everything is fine.  The .Net version on that machine is also 4.0.30319.236.

    Both machines are on WinXP 32bit Professional SP3, 2GB RAM.


    Any ideas?

    Thanks,

    Chris


    • Edited by Skandranon Wednesday, December 14, 2011 8:28 AM incorrect file size
    Wednesday, December 14, 2011 8:16 AM

All replies

  • BadImageException usually occurs due to platform mismatch. I suggest you to try building your project in x86 mode instead of 'Any CPU' or 'X64'.

    Read this excellent blog from Martin Kulov on BadImageExcetion.

    http://blog.kulov.net/2011/09/unhandled-exception-systembadimageforma.html


    Please mark this post as answer if it solved your problem. Happy Programming!
    • Marked as answer by Paul Zhou Wednesday, December 21, 2011 8:30 AM
    • Unmarked as answer by Skandranon Wednesday, December 21, 2011 11:09 AM
    Wednesday, December 14, 2011 11:17 AM
  • It is as Adavesh said, BadImageException always be threw when loading assembly build with wrong platform option. In your case, since the application runs on 32-bit WinXP, you need to build application and referenced assembly with X86 option.

    /platform


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, December 15, 2011 7:41 AM
  • Hi,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    If you still have any questions about this issue, please feel free to let me know. We will continue to work with you on this issue.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, December 21, 2011 8:30 AM
  • Unfortunately my issue is not resolved yet. Using Fusion log I see that the failure happens when the CLR tries to load following assembly: PMA_Tariff_Link.XmlSerializers. This is patently incorrect, but I don't know how to tell the CLR not to load that "assembly" (since I don't have that namespace in my solution, but I use System.Xml for my WCF traffic). ============================================================================= Two Fusion log entries were made. Here they are: *** Assembly Binder Log Entry (19/12/2011 @ 03:58:34 PM) *** The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified. Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\rj\TestUIClient\TestUIClient.exe --- A detailed error log follows. === Pre-bind state information === LOG: User = RECEPTION-NB\User LOG: DisplayName = PMA_Tariff_Link.XmlSerializers (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: PMA_Tariff_Link.XmlSerializers | Domain ID: 1 WRN: A partial bind occurs when only part of the assembly display name is provided. WRN: This might result in the binder loading an incorrect assembly. WRN: It is recommended to provide a fully specified textual identity for the assembly, WRN: that consists of the simple name, version, culture, and public key token. WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. LOG: Appbase = file:///C:/rj/TestUIClient/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = TestUIClient.exe Calling assembly : System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\rj\TestUIClient\TestUIClient.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers.DLL. LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers/PMA_Tariff_Link.XmlSerializers.DLL. LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers.EXE. LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers/PMA_Tariff_Link.XmlSerializers.EXE. LOG: All probing URLs attempted and failed. =================================================== *** Assembly Binder Log Entry (19/12/2011 @ 03:58:34 PM) *** The operation failed. Bind result: hr = 0x80070002. The system cannot find the file specified. Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\rj\TestUIClient\TestUIClient.exe --- A detailed error log follows. === Pre-bind state information === LOG: User = RECEPTION-NB\User LOG: DisplayName = PMA_Tariff_Link.XmlSerializers, Version=1.10.1.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL (Fully-specified) LOG: Appbase = file:///C:/rj/TestUIClient/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = TestUIClient.exe Calling assembly : System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\rj\TestUIClient\TestUIClient.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers.DLL. LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers/PMA_Tariff_Link.XmlSerializers.DLL. LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers.EXE. LOG: Attempting download of new URL file:///C:/rj/TestUIClient/PMA_Tariff_Link.XmlSerializers/PMA_Tariff_Link.XmlSerializers.EXE. LOG: All probing URLs attempted and failed.
    Wednesday, December 21, 2011 11:09 AM
  • You log clearly states that PMA_Tariff_Link.XmlSerializers is missing. Though you say that you have not included the namespace, that assembly is definitely referenced somewhere in the code at runtime. If not directly in your application, PMA_Tariff_Link.XmlSerializers.dll might referenced from other dlls used in your application. Or the assembly may be getting referenced via reflection.

    You can use tools like Reference Walker  or reflector to find all the referenced assemblies of your application.


    Please mark this post as answer if it solved your problem. Happy Programming!
    Wednesday, December 21, 2011 11:48 AM
  • We've shelved this problem for now. There seems to be more wrong with this PC than meets the eye. We've recommended a re-format and installation of WinXP. As for the "XmlSerializers" assembly: It came to light that the framework generates a serialized assembly of the PMA_Tariff_Link.dll during execution. Once we generated it manually (using sgen.exe) the failures noted in the fusion log disappeared. However, this did not resolve the original error. Thanks for the help!
    Thursday, December 22, 2011 5:31 AM