问题
We have a .NET 4, WPF, WCF, EF 4, SQL 2008 application. One of our EF models is highly relational and in the case I'm describing could and probably does contain cycles. I've been asked to troubleshoot a case in the field where all of a sudden data from this STE EF model quit showing up in the WPF client. Upon closer examination, I found that the IIS W3WP process crashes when trying to retrieve (serialize) the STE EF object graph. I used Debug Diagnostics to capture the crash.
When I looked at the generated crash report, I discovered it was a stack overflow exception (how appropriate). The stack trace in the crash report is rather large, but the top of the stack looks something like:
System.Xml.XmlBaseWriter.StartElement(System.String ByRef, System.String, System.String, System.Xml.XmlDictionaryString)
System.Xml.XmlBaseWriter.WriteStartElement(System.String, System.Xml.XmlDictionaryString, System.Xml.XmlDictionaryString)
System.Runtime.Serialization.XmlWriterDelegator.WriteStartElement(System.String, System.Xml.XmlDictionaryString, System.Xml.XmlDictionaryString)
DynamicClass.WriteXXXDataToXml(System.Runtime.Serialization.XmlWriterDelegator, System.Object, System.Runtime.Serialization.XmlObjectSerializerWriteContext, System.Runtime.Serialization.ClassDataContract)
System.Runtime.Serialization.ClassDataContract.WriteXmlValue(System.Runtime.Serialization.XmlWriterDelegator, System.Object, System.Runtime.Serialization.XmlObjectSerializerWriteContext)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(System.Runtime.Serialization.DataContract, System.Runtime.Serialization.XmlWriterDelegator, System.Object, System.RuntimeTypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(System.Runtime.Serialization.XmlWriterDelegator, System.Object, Boolean, Boolean, Int32, System.RuntimeTypeHandle)
System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(System.Runtime.Serialization.XmlWriterDelegator, System.Object, Boolean, Boolean, Int32, System.RuntimeTypeHandle)
What makes exceptionally odd is that when the WCF service is hosted in Visual Studio and I run from the dev environment, the serialization works perfectly, and I get data on the client.
Could this be resolved by IIS settings? Why would it work with Visual Studio's dev IIS, but not with the production IIS?
I'm not sure what is causing this problem or why the serializer is even barfing?
Should I try another means of WCF serialization w/ STE EF4?
Any input is appreciated.
Thanks!
回答1:
(By default) IIS limits stack size of managed threads to 256 KB. I don't know about dev web server but the default stack size for managed threads is 1 MB. In addition if you are running on a 64-bit machine stack frames are in general bigger than stack frames on a 32-bit machine. So, if your dev box is 32-bit you may not see what you see in production. I wrote a little bit about this here http://blogs.msdn.com/b/xmlteam/archive/2011/09/26/effective-xml-part-5-something-went-really-wrong-outofmemoryexception-and-stackoverflowexception-thrown-when-using-xslcompiledtransform.aspx. It is a bit different context but the discussion about IIS, stack sizes and frame sizes still applies.
来源:https://stackoverflow.com/questions/11039450/stackoverflowexception-serializing-ste-ef-object-graph