XmlSerializer.Serialize 上的 NullReferenceException
我们试图将一个类序列化为 XML,但遇到了 NullReferenceException,但我们不知道为什么。我查看了 Visual Studio 调试器中的对象,没有一个对象未初始化。当我们尝试序列化时,displayConfig 中的所有属性都不为空,文件名是正确的。我们在这里很无助。
您可以在 http://pastebin.com/3RwkMMbr 找到代码
问题是:这个 NullReferenceException 来自哪里序列化和反序列化方法抛出的是什么?
编辑: 好的。在另一个应用程序中尝试此操作后,InnerException 从“NullReferenceException”更改为“无法找到 Assemlby $(ProjectName)”之类的内容。我想这很奇怪,我添加了对 bin/Debug 文件夹中的 .dll 的引用,然后它突然就起作用了。我不知道为什么,但是 - 不再有“NullReferenceException”了。连载得很好。在原来的项目中也是如此。
我很困惑。它在我的脑海中创建了一个奇怪的循环来引用我想用此代码创建的 .dll。
We are trying to serialize a class to XML and we get confronted with a NullReferenceException and we cant figure out why. I've looked at the Objects in the Visual Studio debugger, none of them is not initialized. All the properties in displayConfig are not null when we try to serialize, the file name is correct. We are helpless here.
You can find the code at http://pastebin.com/3RwkMMbr
The Question is: Where does this NullReferenceException come from that is thrown by the Methods Serialize and Deserialize?
EDIT:
Ok. After trying this in another application the InnerException changeded from "NullReferenceException" to something like "Could not find Assemlby $(ProjectName)". That was odd, I thought, I've added a reference to the .dll from the bin/Debug folder and suddenly it worked. I don't know why, but - no "NullReferenceException" anymore. It is serializing fine. In the original project as well.
I am confused. It is creating a strange loop in my head to reference the .dll I want to create with this code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在代码中发现的唯一问题是访问 StreamSource(序列化程序执行的操作)会导致堆栈溢出,因为您在 getter 中缺少下划线。
我认为除非您可以提供一些实际重现错误的代码,否则我们将无法帮助您。
The only problem I could find in the code is that accessing
StreamSource
(which the serializer does) causes stack overflow, because you're missing an underscore in the getter.I think that unless you can provide some code that actually reproduces your error, we won't be able to help you.