locked
System.OutofMemoryException exception when creating SOAP object RRS feed

  • Question

  • User-899943225 posted

    Hello everyone,

    I am having a System.OutofMemoryException error when I try to create a SOAP envelope to consume a web service. This is the code having the issue (code is developed in Visual Studio 2008):

    private WSRevisionedMaintSoap setRevMaintHeader()
    {
      RegistryKey Core_RegKey = Registry.LocalMachine.OpenSubKey("Software\\Von\\Inte");
    
      //build service node
      WSRevisionedMaintSoap WSService = new WSRevisionedMaintSoap();
      WSService.WSRevisionedMaintHeaderValue = new WSRevisionedMaintHeader();
      WSService.WSRevisionedMaintHeaderValue.UserName = ConfigurationSettings.AppSettings["inte_nt_user"];
      WSService.WSRevisionedMaintHeaderValue.Password = DecryptPassword(Core_RegKey.GetValue("Encrypted_Password","").ToString());
    
      return WSService;
    }
    

    The code fails at the WSRevisionedMaintSoap WSService = new WSRevisionedMaintSoap(); line (just below the comment line). Here is the stack trace:

    at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)\r\n
    at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)\r\n
    at System.Text.StringBuilder.Append(String value)\r\n
    at System.IO.StringWriter.Write(String value)\r\n
    at System.Xml.Serialization.IndentedWriter.WriteIndent()\r\n
    at System.Xml.Serialization.IndentedWriter.Write(String s)\r\n
    at System.Xml.Serialization.ReflectionAwareCodeGen.WriteArrayLocalDecl(String typeName, String variableName, String initValue, TypeDesc arrayTypeDesc)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.WriteMemberBegin(Member[] members)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.WriteArray(String source, String arrayName, ArrayMapping arrayMapping, Boolean readOnly, Boolean isNullable, Int32 fixupIndex)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.WriteElement(String source, String arrayName, String choiceSource, ElementAccessor element, ChoiceIdentifierAccessor choice, String checkSpecified, Boolean checkForNull, Boolean readOnly, Int32 fixupIndex, Int32 elementIndex)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.WriteMemberElementsIf(Member[] members, Member anyElement, String elementElseString, String checkTypeSource)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.WriteMemberElements(Member[] members, String elementElseString, String elseString, Member anyElement, Member anyText, String checkTypeHrefsSource)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.WriteLiteralStructMethod(StructMapping structMapping)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.WriteStructMethod(StructMapping structMapping)\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.GenerateMethod(TypeMapping mapping)\r\n
    at System.Xml.Serialization.XmlSerializationCodeGen.GenerateReferencedMethods()\r\n
    at System.Xml.Serialization.XmlSerializationReaderCodeGen.GenerateEnd(String[] methods, XmlMapping[] xmlMappings, Type[] types)\r\n
    at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)\r\n
    at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)\r\n
    at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)\r\n
    at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)\r\n
    at System.Web.Services.Protocols.SoapClientType..ctor(Type type)\r\n
    at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()\r\n
    at Cmpss_BLL.InteWServices.WSRevisionedMaintSoap..ctor() in C:\\MyProjects\\Cmpss_Solution\\Cmpss_BLL\\Web References\\InteWServices\\Reference.cs:line 961\r\n
    at Von.BLL.Inte.setRevMaintHeader() in C:\\MyProjects\\Cmpss_Solution\\Cmpss_BLL\\Inte.cs:line 9573\r\n
    at Von.BLL.Inte.Build_Workflow(ArrayList WF_Data, ArrayList WF_LPData, ArrayList WF_AnalTestData) in C:\\MyProjects\\Cmpss_Solution\\Cmpss_BLL\\Inte.cs:line 2294\r\n
    at Von.BLL.Inte.Build_MES_Objects(Object argProtocol_ID) in C:\\MyProjects\\Cmpss_Solution\\Cmpss_BLL\\Inte.cs:line 1727

    This code has run perfectly for years. Just this week we updated the web references in the project because the web services were upgraded to a newer version. After updating the web reference in the project this error started to come up and we have not been able to run past this line.

    What things could possibly cause an out of memory error when trying to instantiate a SOAP object? The machine has sufficient memory installed so we don't think the machine actually getting out of memory is the real cause. I have searched the web for a solution or at least an explanation with no avail. What could be the cause? What should I look for? Please ask any questions if you need more info.

    Thanks in advance.

    C

    Thursday, January 17, 2013 3:10 PM

Answers

  • User-1000095884 posted

    Hi,

    You may use a memory profiling tools(e.g CLRProfiler) to investigate your application's memory allocation profile and check if there is a memory leak(Ant Memory Profiler tool etc).

    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 21, 2013 4:30 AM