Why did I get an error with my XmlSerializer?

假装没事ソ 提交于 2019-11-28 16:40:30

问题


I made a couple of changes to my working application and started getting the following error at this line of code.

Dim Deserializer As New Serialization.XmlSerializer(GetType(Groups))

And here is the error.

    BindingFailure was detected
    Message: The assembly with display name 'FUSE.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null'

    Message: The assembly with display name 'FUSE.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null'

=== Pre-bind state information ===
LOG: User = DOUG-VM\Doug
LOG: DisplayName = FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL
 (Fully-specified)
LOG: Appbase = file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\Laptop\Core Data\Data\Programming\Windows\DotNet\Work Projects\NOP\Official Apps\FUSE WPF\Fuse\bin\Debug\FUSE.vshost.exe.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\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:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers/FUSE.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers.EXE.
LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers/FUSE.XmlSerializers.EXE.

What's going on?


回答1:


The main reason this was happening was because I had a mismatch in the types I was trying to Serialize and Deserialize. I was Serializing ObservableCollection (of Group) and deserializing a business object - Groups which inherited ObservableCollection (of Group).

And this was also part of the problem... From - http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/9f0c169f-c45e-4898-b2c4-f72c816d4b55/

This exception is a part of the XmlSerializer's normal operation. It is expected and will be caught and handled inside of the Framework code. Just ignore it and continue. If it bothers you during debugging, set the Visual Studio debugger to only stop on unhandled exceptions instead of all exceptions.




回答2:


According to information I found, BindingFailure exception associated with XmlSerializers sometimes does not indicate any error and should be just ignored, but you can sometimes see it i. e. in debug mode, when you have set VS options to show all thrown exceptions.

Source: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=88566&wa=wsignin1.0

Btw. this is more or less one of the things mentioned in the first answer :).




回答3:


It appears that you cannot locate the assembly FUSE.XmlSerializers. Check the results of the Assembly Binding Log Viewer (Fuslogvw.exe) to see where it is looking (although the list presented above seems pretty full).

Try to locate where this assembly is stored on your computer and run NGen on it to see if it is failing to load for some reason. Make sure this DLL file is appearing in your Bin\Debug directory. Visual Studio doesn't seem to get the dependencies of dependencies, and so you have to make sure you have all the files you need yourself sometimes.




回答4:


How did you load the assembly containing the Groups type? I'm guessing you loaded it with Assembly.LoadFrom() because the XML serializer is using the same context (the 'LoadFrom' context) to attempt to load assemblies for serialization. If so, you have a couple of options:

  1. Use Assembly.Load() instead of Assembly.LoadFrom().
  2. Attach a handler to AppDomain.AssemblyResolve to help the CLR find the assembly in question.



回答5:


For the select few Visual Studio projects I have where this is an annoyance, I prefer to disable break on exception for just the BindingFailure and the System.IO.FileNotFoundException.

In Visual Studio: Ctl+D, Ctl+E for the Exceptions dialog:

1) Uncheck BindingFailure under Managed Debugging Assistants

2) Uncheck System.IO.FileNotFoundException under Common Language Runtime Exceptions.

Ahhh that’s better :-)

...and I see 1/2 this answer was given by strager Nov 24 '10 at 10:12



来源:https://stackoverflow.com/questions/294659/why-did-i-get-an-error-with-my-xmlserializer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!