IIS Stackoverflow Exception

This is another variation of the same issue when a StackOverflow exception occurs due to the 256K stack size when working in IIS. This problem is not new, and it has been asked several times ( here and here )

My question is a little different. An exception occurs when a client requests data, and a WCF service running under IIS 7 tries to serialize a fairly large graph of objects. This happens during serialization.

I can easily reproduce the problem in a development environment by doing the retrieve / serialize procedure on a thread with a limited stack size:

static void Main(string[] args) { Thread t = new Thread(DoWork, 262144); t.Start(); t.Join(); Console.ReadLine(); } private static void DoWork() { var dataAccess = new DataAccess(); var data = dataAccess.LoadData(); var serializer = new DataContractSerializer(typeof(List<Data>), null, int.MaxValue, false, true, new DataContractSurrogate()); var memoryStream = new MemoryStream(); serializer.WriteObject(memoryStream, data ); } 

This models the StackOverflow exception, as in IIS. When I change the stackSize parameter passed to the Thread constructor to 1MB, it works fine ...

My question is: how can this be done inside the WCF service method? In other words, in my WCF service method, I explicitly do not create a serializer and do not call WriteObject. How / where can I do the same work in a thread, where can I control stackSize?

Thanks!

+7
source share
1 answer

You can change the default stack size by changing the PE header of the executable. Use editbin.exe with the / stack argument. See http://msdn.microsoft.com/en-us/library/35yc2tc3(v=vs.80).aspx

+1
source

All Articles