Invalid program exception in release build (.NET 4.6.1)

旧街凉风 提交于 2019-12-25 08:47:50

问题


I have a program that deals with socket communication asynchronously. The exception I've been getting only occurs in release build (on build machines). The code that causes the problem is really simple routine to start listening for incoming socket connections:

public async Task Listen()
    {
        try
        {
            var endpoint = new IPEndPoint(IPAddress.Loopback, Port);
            using (Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                Socket.Bind(endpoint);
                Socket.Listen(Limit);
                while (!Shutdown)
                {
                    var socket = await Socket.AcceptAsync().ConfigureAwait(false);

                    // some code handling connection

                    var result = await Socket.ReceiveAsync(state).ConfigureAwait(false);
                    Received(result, state);
                }
            }
        }
        catch (ObjectDisposedException) {}
        catch (Exception ex) when (ex is SocketException || ex is ApplicationException || ex is ThreadAbortException)
        {
            OnError?.Invoke(this, ex);
            Dispose();
        }
    }

AcceptAsync and ReceiveAsync are extension methods that use TPL pattern with Task.Factory.FromAsync. The exact exception is following:

Exception Type:        System.InvalidProgramException 
Exception Message:     Common Language Runtime detected an invalid program. 

This seem to occur in:

System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start

The exception is generated instantly when call is made to this method. Any ideas what might be wrong?


回答1:


According to MSDN, this exception informs the user about invalid IL code. So something could be broken in the framework. I recommend you to try your luck at Connect.Microsoft. Also, if you're really interested and are looking for a quick fix you may want to inspect the IL code of the failing methods' chain.



来源:https://stackoverflow.com/questions/39588842/invalid-program-exception-in-release-build-net-4-6-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!