C# XmlSerializer BindingFailure [英] C# XmlSerializer BindingFailure

查看:13
本文介绍了C# XmlSerializer BindingFailure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 XmlSerializer 的一行代码上得到了 BindingFailure:

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

<块引用>

显示名称为 CustomXMLSerializeObject.XmlSerializers' 的程序集未能在 ID 为 1 的 AppDomain 的LoadFrom"绑定上下文中加载.失败的原因是:System.IO.FileNotFoundException:无法加载文件或程序集 XMLSerializeObject.XmlSerializers, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null' 或其依赖项之一.系统找不到指定的文件.

该错误很长,并继续解释预绑定状态信息以及尝试查找文件的位置.

我试图反序列化的自定义对象相对简单——只是一堆具有公共访问器的私有整数和字符串.我确实有一个私有变量,它是另一个自定义的可序列化类,但它只有带有公共访问器的私有字符串.

尴尬的部分?这仅在我反序列化时发生.当我序列化对象时,那行代码运行良好.它工作正常,对象被反序列化并完美填充.不要真正注意到任何性能损失或加载时间过长.

这个警告到底是什么(不是错误或异常,程序运行良好)?为什么会发生?如何在不禁用警告的情况下阻止它?

解决方案

根据 奇怪的 XmlSerializer 错误:

<块引用>

这个异常是XmlSerializer 的正常运行.它预计将被抓住和在框架代码内部处理.只需忽略它并继续.如果它在调试过程中打扰你,设置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

这篇关于C# XmlSerializer BindingFailure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆