C#XmlSerializer的BindingFailureXmlSerializer、BindingFailure

2023-09-02 10:45:21 作者:微醺

我得到的code使用XmlSerializer一个行BindingFailure:

  XmlSerializer的S =新的XmlSerializer(typeof运算(CustomXMLSerializeObject));
 

  

与显示名称CustomXMLSerializeObject.XmlSerializers未能在加载'LoadFrom'结合的AppDomain的上下文ID为1的失败的原因是该组件信息:System.IO.FileNotFoundException:无法加载文件或程序XMLSerializeObject。 XmlSerializers,版本= 1.4.0.0,文化=中性公钥= null或它的一个依赖。该系统找不到指定的文件。

该错误是很长,接着解释pre-绑定状态信息,它看起来,试图找到该文件的位置。

在自定义对象我想desrialize相对比较简单 - 只是一群私人整数,且具有公共访问的字符串。我有是另一个自定义可序列化类中的私有变量,但一个无关但与公众存取私人字符串在里面。

这种尴尬的分手?当我反序列化这只是发生。当我序列化对象行code运行良好。它工作正常和对象被反序列化和填充完美。不要真正注意到的性能或较长的加载时间的任何损失。

到底这是什么警告(不是错误或异常,节目结束之后运行良好)?它为什么会发生?我如何prevent它不只是禁用警告?

解决方案

据Strange XmlSerializer的错误:

  

这是例外的一部分   XmlSerializer的正常运作。它   预计,将被捕获并   框架code内处理。   只要不理它,继续。如果它   在调试过程中困扰你,设置   Visual Studio调试器只停止   未处理的异常,而不是全部   例外情况。

它根据你的例外,你是选择监视可能正在造成的。

你能告诉我你的异常是如何设置:调试 - >例外

如果您在托管调试助手取消抛出复选框的BindingFailure异常应该消失。或者,如果你不想这样做,你可以继续,因为这个异常是由设计

I get a BindingFailure on a line of code using the XmlSerializer:

XmlSerializer s = new XmlSerializer(typeof(CustomXMLSerializeObject));

The assembly with display name CustomXMLSerializeObject.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 XMLSerializeObject.XmlSerializers, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

The error is quite long and goes on to explain pre-bind state information and the places it looked to try and find the file.

The custom object I am trying to desrialize is relatively simple - just a bunch of private integers and strings that have public accessors. I do have a private variable that is another custom serializeable class but that one has nothing but private strings with public accessors in it.

The awkward part? This only happens when I deserialize. That line of code runs fine when I serialize the object. It works fine and the object gets deserialized and populated perfectly. Don't really notice any loss of performance or long loading time.

What exactly is this warning (not an error or exception, program runs fine afterwards)? Why does it happen? How do I prevent it without simply disabling the warning?

解决方案

According to Strange XmlSerializer error:

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.

Its probably being caused based on your exceptions that you are choosing to monitor.

Can you tell me how your exceptions are setup: Debug -> Exceptions

If you uncheck the "Thrown" checkbox for the BindingFailure under the Managed Debugging Assistants the exception should go away. Or if you dont want to do this, you can just continue since this exception is by design