I get a "System.StackOverflowException" in my .NET MVC project after the View has been sent to the client. The view is displayed correctly, so the client side does not see the error. However, after that, the server crashes with a StackOverflow Exception. I tested this only in IISExpress / VisualStudio and not in IIS.
I have html files on a remote server. I upload html files as follows:
using (WebClient client = new WebClient() {Credentials = new NetworkCredential(Username, Password)}) { string html = client.DownloadString(url); viewModel.Pages.Add(html); }
Where "Pages" may contain multiple html fragments. However, the test page I use is a full html page with the nodes "doctype", "head", "body", etc.
In my view, I create the page as follows:
foreach(var page in Model.Pages) { @Html.Raw(page) }
As I said, the page displays correctly, but after that the server crashes. I do not see any recursive calls. I tried to use the Debug Diag tool for troubleshooting, but was not able to receive any alarm messages.
In addition, if I draw a "page" without @ Html.Raw (), the crash does not occur (however, the page does not display correctly, for example, the LT / GT brackets are replaced with "&" / "& lt;", among other characters)
I suspect this may have something to do with the length of the "html" line or the content of the page. I have another Sitemap page that is simpler, loads correctly and does not cause a server error.
Exceptions also occur in different places: System.Web.dll, mscorlib.dll and System.Runtime.Serialization.dll
How to fix this StackOverflow exception?
Is there a limit on the size of the string that can be displayed using @ Html.Raw ()?
External stack trace:
System.Runtime.Serialization.dll! System.Runtime.Serialization.Json.XmlJsonWriter.HasOpenAttribute.get () Unknown System.Runtime.Serialization.dll! System.Runtime.Serialization.Json.XmlJsonWriter.WriteState.get () Unknown System.Runtime.Serialization.dll! System.Runtime.Serialization.Json.XmlJsonWriter.WriteStartAttribute (string prefix, localName string, ns string) System.Xml.dll is unknown! System.Xml.XmlWriter.WriteAttributeString (string localName, string value) Unknown System.Runtime.Serialization.dll! System.Runtime.Serialization.Json.JsonWriterDelegator.WriteInt (value int) Unknown System.Runtime.Serialization.dll! System.Runtime.Serialization.IntDataContract.WriteXmlValue (System.Runtime.Serialization.XmlWriterDelegator writer, object obj, System.Runtime.Serialization.XmlObjectSerializerWriteContext context) Unknown System.Runtime.Serialization.dll! System.Runtime.Serialization.Json.JsonDataContract.WriteJsonValueCore (System.Runtime.Serialization.XmlWriterDelegator jsonWriter, obj object, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.RuntimeANDypepepepe System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle.unknown System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, obj object, bool verifyKnownType, System.RuntimeTypeHandle obyavlenTypeHandle, System.Type declareType) Unknown System.Runtime.Serialization .dll! System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.SerializeWi thank you siType (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, obj object, System.RuntimeTypeHypepepepepepepeaturepepexpexTypeTypeTpepeTpepeTpepeTpepeTpepeTpepeTepeTpepeTepeTpepeTepeTpepeTeTpepeTepeTpepeTeTpeTpepeTepeTpepeTeTpepeTepeTpepeTeTpepeTepeTpepeTeTpepeTepeTepeTpepeTepeTpepeTeTepepepeitTepeTpepeTepeTpepepecode, one, one again, advertised,, declared Runtime.Serialization.dll! System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, obj object, bool isDeclaredType, bool writeXsiType, int declTypeID, System.RuntimeTypeHandle unknown System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, obj object, bool isDeclaredType, bool writeXsiType, int declTypeID, System.RuntimeHent functionTypeNume function) UnknownType function
System.Runtime.Serialization.dll! System.Runtime.Serialization.Json.JsonCollectionDataContract.WriteJsonValueCore (System.Runtime.Serialization.XmlWriterDelegator jsonWriter, obj object, System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson context, System.Randime.lementimendleleimetlementimentleleimetlementimentleleimetlementimentleleimetlementimentleleimetlementimentlementime System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.WriteDataContractValue (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, System.RuntimeTypeHandle.unknown System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, obj object, bool verifyKnownType, System.RuntimeTypeHandle obyavlenTypeHandle, System.Type declareType) Unknown System.Runtime.Serialization .dll! System.Runtime.Serialization.Json.XmlObjectSerializerWriteContextComplexJson.SerializeWi thank you siType (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, obj object, System.RuntimeTypeHypepepepepepepeaturepepexpexTypeTypeTpepeTpepeTpepeTpepeTpepeTpepeTepeTpepeTepeTpepeTepeTpepeTeTpepeTepeTpepeTeTpeTpepeTepeTpepeTeTpepeTepeTpepeTeTpepeTepeTpepeTeTpepeTepeTepeTpepeTepeTpepeTeTepepepeitTepeTpepeTepeTpepepecode, one, one again, advertised,, declared Runtime.Serialization.dll! System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, obj object, bool isDeclaredType, bool writeXsiType, int declared TypeID, System.RuntimeTypeHend.hp System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize (System.Runtime.Serialization.XmlWriterDelegator xmlWriter, object obj, bool isDeclaredType, bool writeXsiType, int declTypeID, System.RuntimeHtypepepe
Part of the [Easy Function] is completely repeated until the failure.
Edit:
Just found this error (among other things) in the "Output" window: an exception appeared in mscorlib.dll with the first probability of the type "System.UnauthorizedAccessException"