Here is what I have tr开发者_Python百科ied:
- Change the directory in which the temp files are stored. (Changed locally to each website).
- Store the XMLSerialization object in a global variable and use that instead of creating a new one each time.
- Delete all temp files in the windows temp folder.
- Set permissions on the windows\temp folder (I have them set to everyone at the moment just to try and resolve the issue).
My Setup is as follows:
IIS7 on windows 2008 dedicated server. The website is written in ASP.NET using Delphi. I have several XML files that need serializing so not just one. My website talks to the web service and processes the XML (I am guessing this is the part that is breaking everything)
Does anyone have any suggestions other than what is listed? I have read about using SGEN to pre-compile the serialization object but will this work for more than one XML file? I don't really know much about it.
Here is an example:
This is the code for one of my XML files. StockXMLSer is held globally and after testing is only created once per site.
function IntGetSTOCK_ITEMS(S: TStream): STOCK_ITEMS;
begin
if not Assigned(StockXMLSer) then begin
StockXMLSer := XmlSerializer.Create(STOCK_ITEMS.ClassInfo);
OutputDebugString('StockXMLSer Serializer Created');
end;
Result := STOCK_ITEMS(StockXMLSer.Deserialize(S));
end;
You will need to add some settings to your code in order to be able debug your serialization code. Please consult the following article on msdn.
Troubleshooting Common Problems with the XmlSerializer
Also there is a neat trick there that will keep the files created in your temp folder so you can see what is happening.
Under normal circumstances, the XmlSerializer deletes the C# source files for the serialization classes when they are no longer needed. There is an undocumented diagnostics switch, however, which will instruct the XmlSerializer deletes to leave these files on your disk. You can set the switch in your application's .config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4" />
</switches>
</system.diagnostics>
</configuration>
With this switch present in the .config file, the C# source files stay in your temp directory. If you are working on a computer running Windows 2000 or later, the default location for the temp directory is \Documents and Settings\\LocalSettings\Temp or \Temp, for web applications running under the ASPNET account. The C# files are easy to miss because they have very odd looking, randomly generated filenames, something like: bdz6lq-t.0.cs. The XmlSerializerPreCompiler sets this diagnostics switch, so you can open the files to inspect the lines on which the XmlSerializerPreCompiler reported compilation errors in Notepad or Visual Studio.
Just for the record, I had an error similar to this one and found the solution from this blog
After setting the permissions on the TEMP folder, the functionality that the error had started to work again.
XML Serialization creates a temporary DLL with the serialization code in it, somewhere in the temp directory. This is loaded into your App Domain when the serializer is created. It's possible that you are deleting this DLL when you clear the Temp directory, and for some reason, it's not getting regenerated correctly.
精彩评论