views:

179

answers:

2

It appears our application has an assembly leak. I noticed that on any calls where a web service call is invoked using the HttpWebRequest object a dynamic assembly is loaded on the call httpWebRequest.GetResponse()

I can see the assembly get loaded through the debugger ('w3wp.exe' (Managed): Loaded '7-6jav6v', No symbols loaded.) but I cannot figure out why this would occur.

Has anyone else experienced this before?

Edit: To add clarifications to this question. In c# when you create an XmlSerializer an assembly is created to complete the serialization. This always will occur unless you use a tool to do this for you in advance. If you use the constructor of (Type type) or (Type type, string "namespace") then only 1 assembly will be generated. If you use any other constructor then a new assembly will be generated for each serialization.

THis is not the case in the problem stated above.

There is a block of code in our codebase that manually makes a soap call and returns a string (the string is xml, ex: ). Each time this block of code executes a new assembly gets created. When examining one of these assemblies this is referenced "XmlSerializationWriter1.Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.XmlSerializer1.ArrayOfObjectSerializer.ArrayOfObjectSerializer1.ArrayOfObjectSerializer2"

For a better understanding - the code block looks like below and when the last line executes the assembly gets generated...multiple assemblies, one for each time this block runs.

HttpWebRequest oHttpWebRequest =(HttpWebRequest)WebRequest.Create("URL TO WEBSERVICE"); 
oHttpWebRequest.Timeout =((1000*60)*30);
oHttpWebRequest.Method ="POST" ; 
oHttpWebRequest.ContentType ="text/xml" ; 
oHttpWebRequest.Headers.Add("SOAPAction: http://www.tempuri.com/"+WebMethodName); 
StreamWriter oStreamWriter = new StreamWriter(oHttpWebRequest.GetRequestStream()) ; 

string SoapRequest=@"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""&gt;&lt;soap:Body&gt;";
SoapRequest=SoapRequest + HttpUtility.HtmlDecode(XmlHttpRequestData);
SoapRequest=SoapRequest + @"</soap:Body></soap:Envelope>";
oStreamWriter.Write(SoapRequest); 
oStreamWriter.Close();

oHttpWebRequest.ProtocolVersion.Build;

WebResponse oWebResponse = oHttpWebRequest.GetResponse() ; 
+1  A: 

According to your comment below Sky Sanders' answer, the generated assemblies are for XML serialization. Serialization assemblies are dynamically generated, unless you pre-generate them using the XML Serializer Generator Tool (Sgen.exe). If you do that, the existing assemblies will be used and no assembly will be generated

Thomas Levesque
Yes - if you do not generate the assemblies using the tool specified, then an assembly will be generated automatically. The problem is - the system is continually generating new assemblies.The assemblies reference XmlSerializationWriter1.Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.XmlSerializer1.ArrayOfObjectSerializer.ArrayOfObjectSerializer1.ArrayOfObjectSerializer2
Dan
I am going to attempt to see how generating the xml serializer up front does and I'll post that test in the morning.
Dan
A: 

Is the schema of the xml for the web services you call fixed, or dynamic? If you are calling arbitrary web services that each take arbitrary XML messages as input and return arbitrary XML messages as output...then the XmlSerializer is going to create a new assembly for each schema. If each message essentially uses the same schema, but varies enough in structure, even though they could use a common schema, the XmlSerializer is only so capable...its going to generate a assembly to handle each specific schema it identifies.

Like Thomas said, if your schema is fixed, use the XML Serializer Generator Tool to pre-generate your serialization assemblies.

jrista