wpf 为什么我的 XmlSerializer 出现错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/294659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:47:57  来源:igfitidea点击:

Why did I get an error with my XmlSerializer?

wpfsystem.xml

提问by Doug

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?

这是怎么回事?

回答by Doug

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).

发生这种情况的主要原因是我尝试序列化和反序列化的类型不匹配。我正在序列化 ObservableCollection(组)并反序列化一个业务对象 - 继承 ObservableCollection(组)的组。

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

这也是问题的一部分......来自 - 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.

此异常是 XmlSerializer 正常操作的一部分。它是预期的,并将在框架代码中被捕获和处理。只需忽略它并继续。如果它在调试过程中困扰您,请将 Visual Studio 调试器设置为仅在未处理的异常而不是所有异常上停止。

回答by Lukasz M

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.

根据我发现的信息,与 XmlSerializers 关联的 BindingFailure 异常有时不表示任何错误,应该忽略,但有时您可以在调试模式下看到它,即当您设置 VS 选项以显示所有抛出的异常时。

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

来源: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 :).

顺便提一句。这或多或少是第一个答案中提到的事情之一:)。

回答by Brody

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).

您似乎无法找到程序集 FUSE.XmlSerializers。检查程序集绑定日志查看器(Fuslogvw.exe) 的结果以查看它的位置(尽管上面显示的列表似乎很满)。

Try to locate where this assembly is stored on your computer and run NGenon it to see if it is failing to load for some reason. Make sure this DLL file is appearing in your Bin\Debugdirectory. 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.

尝试找到此程序集在您的计算机上的存储位置并在其上运行NGen以查看它是否由于某种原因无法加载。确保此 DLL 文件出现在您的Bin\Debug目录中。Visual Studio 似乎没有获取依赖项的依赖项,因此有时您必须确保自己拥有自己需要的所有文件。

回答by Kent Boogaart

How did you load the assembly containing the Groupstype? 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:

你是如何加载包含该Groups类型的程序集的?我猜你加载它是Assembly.LoadFrom()因为 XML 序列化程序使用相同的上下文('LoadFrom' 上下文)来尝试加载程序集以进行序列化。如果是这样,您有几个选择:

  1. Use Assembly.Load()instead of Assembly.LoadFrom().
  2. Attach a handler to AppDomain.AssemblyResolveto help the CLR find the assembly in question.
  1. 使用Assembly.Load()代替Assembly.LoadFrom()
  2. 附加一个处理程序以AppDomain.AssemblyResolve帮助 CLR 找到有问题的程序集。

回答by ScottWelker

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

对于少数几个让我感到烦恼的 Visual Studio 项目,我更喜欢仅针对BindingFailureSystem.IO.FileNotFoundException禁用异常中断。

In Visual Studio: Ctl+D, Ctl+Efor the Exceptions dialog:

在 Visual Studio 中:Ctl+ D, Ctl+E用于异常对话框:

1) Uncheck BindingFailure under Managed Debugging Assistants

1) 在Managed Debugging Assistants下取消选中 BindingFailure

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

2) 在Common Language Runtime Exceptions下取消选中 System.IO.FileNotFoundException 。

Ahhh that's better :-)

啊,这样更好:-)

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

...我看到 1/2 这个答案是由 strager 于 10 年 11 月 24 日 10:12 给出的