Work-around for C# CodeDom causing stack-overflow (CS1647) in csc.exe?

前端 未结 5 2239
滥情空心
滥情空心 2021-01-12 14:20

I\'ve got a situation where I need to generate a class with a large string const. Code outside of my control causes my generated CodeDom tree to be emitted to C# source and

5条回答
  •  醉酒成梦
    2021-01-12 15:18

    I have no idea how to change the behavior of the code generator, but you can change the stack size that the compiler uses with the /stack option of EditBin.EXE.

    Example:

    editbin /stack:100000,1000 csc.exe 
    

    Following is an example of its use:

    class App 
    {
        private static long _Depth = 0;
    
        // recursive function to blow stack
        private static void GoDeep() 
        {
            if ((++_Depth % 10000) == 0) System.Console.WriteLine("Depth is " +
                _Depth.ToString());
            GoDeep();
        return;
        }
    
        public static void Main() {
            try 
            {
                GoDeep();
            } 
            finally 
            {
            }
    
            return;
        }
    }
    
    
    
    
    editbin /stack:100000,1000 q.exe
    Depth is 10000
    Depth is 20000
    
    Unhandled Exception: StackOverflowException.
    
    editbin /stack:1000000,1000 q.exe
    Depth is 10000
    Depth is 20000
    Depth is 30000
    Depth is 40000
    Depth is 50000
    Depth is 60000
    Depth is 70000
    Depth is 80000
    
    Unhandled Exception: StackOverflowException.
    

提交回复
热议问题