本文介绍了XmlSerializer - 第一个反序列化非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目的解决方案;一个asp.net MVC应用程序和一个类库。让我们称它们为项目MVC和项目CLS。


在项目CLS中,我用来创建两个XSD文件的两个不同版本(V1和V2)可序列化的类具有相同的名称,但在不同的命名空间(V1和V2)下使用xsd2code。


在MVC项目中,当用户上传XML文件时,  CLS.dll  
用于反序列化XML成为一个对象。当XML文件是V1类型时,反序列化非常快,但V2版本的XSD文件要复杂得多,反序列化可能需要几分钟,而且只是第一次(它是
之后非常快,直到再次运行应用程序。)


我使用Sgen.exe   工具创建一个序列化程序集( CLS.XmlSerializers.dll
为CLS.V2类型,以消除首次创建程序集在飞行中,因此提高了性能。


我成功了设法将Sgen任务添加到Post Build事件,并且程序集  CLS.XmlSerializers.dll   是每次构建项目时创建的
。另外,我知道程序集是但是,仍然是第一次对XML文件进行反序列化时,需要很长时间。所以,还是应该有些错误。但是,我不知道是什么。请帮助。

解决方案

I have a solution with two projects; an asp.net MVC application, and a class library. Let's call them project MVC and project CLS.

In the project CLS, there are two different versions (V1 and V2) of an XSD file that I have used to create two serializable classes with the same name, but under different namespaces (V1 and V2) using xsd2code.

In the MVC project, when the user uploads an XML file, the CLS.dll is used to deserialize the XML into an object. When the XML file is of type V1, the deserialization is very fast, but the XSD file for the V2 version is a lot more complex, and the deserialization can take up to a couple of minutes, only the first time (it's very fast afterwards, until the application is run again).

I used the Sgen.exe tool to create a serializer assembly (CLS.XmlSerializers.dll) for the CLS.V2 type in order to eliminate the first-time creation of the assembly on the fly, and therefore improving the performance.

I have successfully managed to add the Sgen Task to the Post Build events, and the assembly CLS.XmlSerializers.dll is created every time I build the project. Also, I know that the assembly is loaded. However, still, the first time the XML file is deserialized, it takes a long time. So, something still should be wrong. But, I don't know what. Please help.

解决方案


这篇关于XmlSerializer - 第一个反序列化非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 01:24