views:

395

answers:

2

Hi All,

I know this question has been asked many times and I have done some extensive research on the internet to try and resolve the issue but everything I have tried has failed and I really need to sort this issue out, hence my post. Here is what I have tried:

  1. Change the directory in which the temp files are stored. (Changed locally to each website).
  2. Store the XMLSerialization object in a global variable and use that instead of creating a new one each time.
  3. Delete all temp files in the windows temp folder.
  4. 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;

Thanks in advance.

+2  A: 

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.

Nick
+1 I did not mentioned this concept in my answer
gyurisc
I have only deleted the .dll's once so this would not be the case for my situation but I agree this would be a problem. +1 (sorry not been on the forum long, so forget to plus things up).
webnoob
+1  A: 

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:

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.

gyurisc
For some reason the xml part is not showing up in my answer: <?xml version="1.0" encoding="utf-8" ?><configuration> <system.diagnostics> <switches> <add name="XmlSerialization.Compilation" value="4" /> </switches> </system.diagnostics></configuration>
gyurisc
If I add the code in to keep the files in the temp folder, surely that will resolve the issue because it should always be able to find the dll's. Is that correct?
webnoob
I think your problem is different from adding the code to the temp folder. I guess that the dll is missing because it never gets created for some reason. compilation for example. you will need to find that reason and fix it and you will be fine.
gyurisc
I think it is getting created, I have added the code in and now I have a few more dll's in the temp folder. After inspecting them, they are for my various XML file to deserialize them. This issue doesn't always happen so I guess it must create them (and seeing as I have the saved files now, I guess that confirms it). I didn't get an error last night so it is looking good.
webnoob
QUESTION: Would there be anything stopping me from grabbing these dll's and using them in my project to de-serialize? I haven't managed to get SGEN working so would this be a viable solution? p.s If I don't encounter any problems in the next day or 2 I will mark your post as an answer Gadget, thanks.
webnoob
It would not stop you it is just impractical, you may change the target class somehow that would break the serialization code. It is better to keep this dynamic. Another idea, can you take out the xml and just create a console app that would serialize and deserialize your data. This way you would be able to take out the webserver from the problem space.
gyurisc
I marked this as the answer because it is the closest I have been to resolving it. Not deleting the .dll's is sorting the issues as a temp fix. Thanks.
webnoob