XML 对象反序列化也动态编译?
来源:互联网 发布:java compareto 编辑:程序博客网 时间:2024/04/30 06:37
今天碰到了个非常奇怪的问题,而且无法重现。
在一个类构造的时候从 xml 文件反序列化一个对象。一般情况下都是好,极少数情况下会出现一下问题。
System.Runtime.InteropServices.ExternalException: Timed out waiting for a program to execute. The command being executed was "c:/windows/microsoft.net/framework/v1.1.4322/csc.exe" /noconfig @"C:/DOCUME~1/montaq~1/LOCALS~1/Temp/prfmes01.cmdline".
at System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(IntPtr userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine)
at System.CodeDom.Compiler.Executor.ExecWaitWithCapture(IntPtr userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine)
at System.CodeDom.Compiler.CodeCompiler.Compile(CompilerParameters options, String compilerDirectory, String compilerExe, String arguments, String& outputFile, Int32& nativeReturnValue, String trueArgs)
at System.CodeDom.Compiler.CodeCompiler.FromFileBatch(CompilerParameters options, String[] fileNames)
at System.CodeDom.Compiler.CodeCompiler.FromSourceBatch(CompilerParameters options, String[] sources)
at System.CodeDom.Compiler.CodeCompiler.FromSource(CompilerParameters options, String source)
at System.CodeDom.Compiler.CodeCompiler.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSource(CompilerParameters options, String source)
at System.Xml.Serialization.Compiler.Compile()
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at XmlState..ctor(String path)
at AutoUpdateingAddin.Updater..ctor(String hostAppExeFullPath)
at AutoUpdateingAddin.Form1.CheckUpdate()
at AutoUpdateingAddin.Form1.Form1_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
xml 文件不便,程序也不变,有时候就会有这样的错误。
从这个错误看出来,对象反序列化的时候,会调用动态编译,首先动态的生成一些代码,然后再去编译执行。hoho,中间结果都放在temp文件中。执行结束的时候,delete他。
用reflector 验证了一下,果然如此。(y)
为了测试,我写一个简单的反序列化程序
新建一个类
using System.Xml;
using System.Xml.Serialization;
namespace XmlDemo
{
[XmlRoot("Person",Namespace="")]
public class Person
{
[XmlElement("PersonName")]
public string Name;
public int Age;
}
}
然后我生成一个该类的实例并把它写道xml 文件。文件内容如下
- <Person xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<PersonName>Montaque</PersonName>
<Age>30</Age>
</Person>
代码如下
System.IO.FileStream fs=new System.IO.FileStream("c://test.xml",System.IO.FileMode.Open ,System.IO.FileAccess.Read);
Person p =(Person)xr.Deserialize(fs);
Console.WriteLine(p.Name);
运行结果没有问题。
运行过程中,我用文件监视器坚实了一下csc.exe ,果然他先生成一下中间的cs,然后编译。。。
如下图
- XML 对象反序列化也动态编译?
- 对象序列化反序列化为xml
- XML字符串反序列化为对象
- 对象序列化成XML存储,XML反序列换成对象
- 序列化对象为xml,从xml反序列化
- .NET对象的XML序列化和反序列化
- 使用XML 序列化和反序列化类对象的方法
- .NET对象的XML序列化和反序列化
- C#对象的 Xml序列化与反序列化
- .NET对象的XML序列化和反序列化
- .NET对象的XML序列化和反序列化
- C# 对象的xml序列化和反序列化
- 对象的Xml序列化和反序列化
- 对象的xml序列化、反序列化
- xml序列化及反序列化.net对象
- XmlSerializer 对象的Xml序列化和反序列化
- 对象与XML,序列化与反序列化
- Xml与对象之间的序列化、反序列化
- 请问怎样把FLASH的SWF文件用DELPHI做成一个应用程序文件?
- ORACLE操作BLOB字段
- J2ee应用程序结合水晶报表:例程研究
- 聆听James Rumbaugh的演讲
- [全程建模]关于原型法的讨论——与Wonder的对话
- XML 对象反序列化也动态编译?
- 如何配置tomcat4.x来运行jrc10
- 不刷新页面筛选数据库中的数据
- 不刷新页面改变下拉菜单内容
- 防止表单重复提交的巧妙方法
- 软件的架构设计
- 网页表单验证代码的改进
- [转载]动态创建下拉菜单
- 一条sql 语句搞定数据库分页