Monodroid链接Sdk程序集在Mono库中导致SIGSEGV

时间:2014-03-22 00:35:05

标签: xamarin.android xamarin mvvmcross

我使用C#Android代码在使用共享运行时(Mono)或链接Sdk程序集时工作正常,但当两者都存在时,它会停止工作。我可以使用无链接构建,不使用共享运行时并且运行完美,但是当我尝试打包进行部署(Sdk链接和无共享运行时)时,我得到了一个SIGSEGV:

03-22 08:23:56.486 E/mono-rt ( 2526): Stacktrace:
03-22 08:23:56.486 E/mono-rt ( 2526): 
03-22 08:23:56.496 E/mono-rt ( 2526):   at <unknown> <0xffffffff>
03-22 08:23:56.496 E/mono-rt ( 2526):   at (wrapper managed-to-native) System.Net.Sockets.Socket.SetSocketOption_internal (intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&) <IL 0x0002a, 0xffffffff>
03-22 08:23:56.496 E/mono-rt ( 2526):   at System.Net.Sockets.Socket.SetSocketOption (System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object) <IL 0x000c2, 0x004cf>
03-22 08:23:56.496 E/mono-rt ( 2526):   at Keiser.Plugin.Socket.NetSocket.CreateListeningSocket () [0x00041] in d:\Development\Keiser.MPM.Screen\Keiser.Plugin.Socket.Droid\NetSocket.cs:73
03-22 08:23:56.496 E/mono-rt ( 2526):   at Keiser.Plugin.Socket.NetSocket.StartListener (System.AsyncCallback) [0x00012] in d:\Development\Keiser.MPM.Screen\Keiser.Plugin.Socket.Droid\NetSocket.cs:92
The program 'Mono' has exited with code 0 (0x0).

我的代码中的最后一个方法是:

    protected virtual void CreateListeningSocket()
    {
        lock (Locker)
        {
            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, _port);
            _socket.Bind(ipEndPoint);
            _socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(_ipAddress)));
            _endPointSender = new IPEndPoint(IPAddress.Any, 0);
        }
    }

我有什么方法可以解决这个问题吗?我已尝试使用UDPClient进行重构,但它在我调用UDPClient对象上的JoinMulticastGroup的行上给出了相同的错误。这是monodroid装配体内的错误吗?

**注意:此代码位于MvvmCross插件中,该插件由Core PCL为项目引用,该项目本身是由Android项目引用的。

2 个答案:

答案 0 :(得分:4)

我仍然不知道为什么会这样,但我找到了解决方案。

在Android解决方案属性中,在Android选项选项卡下,选中了发布配置,我使用了SDK Assemblies Only链接,并将System添加到Skip链接程序集选项,并禁用了“Use Shared Runtime”。

这使得APK文件稍大一些,但不是很多(在我的情况下,10.1Mb对9.8Mb)。

答案 1 :(得分:1)

现在我知道如何重现它,将它发送给Xamarin。它在调用JoinMulticastGroup并在后台启动另一个套接字操作时发生。 https://bugzilla.xamarin.com/show_bug.cgi?id=22183可在Mono 5.4中重现。解决方法是在执行任何其他套接字操作之前加入JoinMulticastGroup。

相关问题