Is XML Object deserialization also dynamically compiled?

Source: Internet
Author: User

Today, we encountered a very strange problem that cannot be reproduced.

Deserializes an object from an XML file during class construction. Generally, it is good. In rare cases, problems may occur.

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: \ police ~ 1 \ montaq ~ 1 \ locals ~ 1 \ temp \ prfmes01.20.line ".
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, string defaultnamespace)
At system. xml. serialization. xmlserializer .. ctor (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 file inconvenience,ProgramAnd sometimes there will be such errors.

This error indicates that dynamic compilation is called during object deserialization.CodeAnd then compile and execute. Hoho, the intermediate results are all placed in the temp file. When the execution ends, delete it.

Verify it with reflector. (Y)

To test, I write a simple deserialization program.

Create a class

Using System;
Using System. xml;
Using System. xml. serialization;

Namespace Xmldemo
{

[Xmlroot ( " Person " , Namespace = "" )]
Public   Class Person
{
[Xmlelement ("Personname")]
Public StringName;

Public IntAge;
}
}

Then I generate an instance of this class and write it into an XML file. The file content is as follows:

  <? XML version = "1.0" ?>  
- < 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 >

Next is the deserialization class. Remember to reference system. runtime. serialization. dll.

The Code is as follows:

System. xml. serialization. xmlserializer XR = New System. xml. serialization. xmlserializer ( Typeof (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 );

The running result is correct.

During the running process, I used the file vendor to install csc.exe. He really made a CS in the middle and then compiled it...

For example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.