Xamarin:libmonosgen-2.0.dylib:MCNearbyServiceAdvertiser 上缺少必需的代码签名

Posted

技术标签:

【中文标题】Xamarin:libmonosgen-2.0.dylib:MCNearbyServiceAdvertiser 上缺少必需的代码签名【英文标题】:Xamarin: libmonosgen-2.0.dylib: required code signature missing on MCNearbyServiceAdvertiser 【发布时间】:2018-03-14 21:45:16 【问题描述】:

我正在使用来自 a working code-only approach 的 MultiPeer 框架并将其移动到 into a MVVM structure 并得到以下异常。

我在两台不同的计算机上使用 Mac OS High Sierra,每台都有 iPhone running my MVVM instance.

我已经仔细检查了纯代码方法,甚至在实例中使用了属性(而不是字段)。这似乎是 Xamarin 绑定或链接器问题。

NearbyDevicesViewController.cs/MCNearbyServiceAdvertiser - 损坏

public partial class NearbyDevicesViewController : UITableViewController

    public string myPhoneName  get; set; 
    public  MCPeerID myPeerID  get; set; 
    public const string SERVICE_STRING = "AELP";
    public MCSession Session  get; set; 

    List<PeerMonitorStatus> CachedPeerStatus = new List<PeerMonitorStatus>();

    public NearbyDevicesViewController (IntPtr handle) : base (handle)
    
        myPhoneName = "A" + UIKit.UIDevice.CurrentDevice.Name; // Adding A prefix incase numeric isn't allowed (it's a problem in Windows NETBios... so maybe also here?)
        MyPhoneStatus.MyPeerID =  myPhoneName;
        myPeerID = new MCPeerID(myPhoneName);

        Session = new MCSession(myPeerID);
        Session.Delegate = new ChatSessionDelegate(Session);
        //--------------------------------Advertiser----------------------------------------------------
        var emptyDict = new NSDictionary();
        AppDelegate.advertiser = new MCNearbyServiceAdvertiser(myPeerID, emptyDict, SERVICE_STRING);
        AppDelegate.advertiser.Delegate = new MyNearbyAdvertiserDelegate(this);

        System.Diagnostics.Debug.WriteLine("Starting advertising...");
        AppDelegate.advertiser.StartAdvertisingPeer();
        MyPhoneStatus.IsAdvertising = true;

        ////--------------------------------Browser------------------------------------------------------
        //AppDelegate.browser = new MCNearbyServiceBrowser(myPeerID, SERVICE_STRING);
        //AppDelegate.browser.Delegate = new MyBrowserDelegate(myPeerID, Session);

        //System.Diagnostics.Debug.WriteLine("Starting browsing...");
        //AppDelegate.browser.StartBrowsingForPeers();
        //MyPhoneStatus.IsBrowsing = true;

        CachedPeerStatus.AddRange(AppDelegate.PeerHistoryMonitor.Values);
    

    public override nint RowsInSection(UITableView tableView, nint section)
    
        return CachedPeerStatus.Count;
    

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    
        UITableViewCell cell = new UITableViewCell(CGRect.Empty);
        var item = CachedPeerStatus[indexPath.Row];

        cell.TextLabel.Text = item.DisplayText;
        return cell;
    

AdvertiserController/MCNearbyServiceAdvertiser - 工作中

public class AdvertiserController : DiscoveryViewController

    MCNearbyServiceAdvertiser advertiser;

    public AdvertiserController(string peerID) : base(peerID)
    
    

    public override void DidReceiveMemoryWarning()
    
        // Releases the view if it doesn't have a superview.
        base.DidReceiveMemoryWarning();

        // Release any cached data, images, etc that aren't in use.
    

    public override void ViewDidLoad()
    
        base.ViewDidLoad();

        View = new DiscoveryView("Advertiser", this);
        var emptyDict = new NSDictionary();
        Status("Starting advertising...");

        advertiser = new MCNearbyServiceAdvertiser(PeerID, emptyDict, SERVICE_STRING);
        advertiser.Delegate = new MyNearbyAdvertiserDelegate(this);
        advertiser.StartAdvertisingPeer();
    

MyNearbyAdvertiserDelegate.cs - 损坏

public  class MyNearbyAdvertiserDelegate : MCNearbyServiceAdvertiserDelegate

    MCSession session;

    public MyNearbyAdvertiserDelegate(NearbyDevicesViewController session)
    
        this.session = session.Session;
    

    public override void DidReceiveInvitationFromPeer(MCNearbyServiceAdvertiser advertiser, MCPeerID peerID, NSData context, MCNearbyServiceAdvertiserInvitationHandler invitationHandler)
    
        System.Diagnostics.Debug.WriteLine("Advertiser [" + session.MyPeerID.GetNativeHash() + "] will accept invite from " + peerID.DisplayName + " [" + peerID.GetNativeHash() + "]");

        MyPhoneStatus.LastInvitation = DateTime.UtcNow;

        MyPhoneStatus.ConnectedPeers.Clear();
        MyPhoneStatus.ConnectedPeers.AddRange(session.ConnectedPeers);

        invitationHandler(true, session); 
    

MyNearbyAdvertiserDelegate - 工作中

class MyNearbyAdvertiserDelegate : MCNearbyServiceAdvertiserDelegate

    AdvertiserController parent;

    public MyNearbyAdvertiserDelegate(AdvertiserController parent)
    
        this.parent = parent;
    

    public override void DidReceiveInvitationFromPeer(MCNearbyServiceAdvertiser advertiser, MCPeerID peerID, NSData context, MCNearbyServiceAdvertiserInvitationHandler invitationHandler)
    
        parent.Status("Received Invite");
        invitationHandler(true, parent.Session);
    

测试环境

我有两个 Mac+iPhone 硬件组合。无论哪台机器是广告商,都会出现此问题。如果代码作为服务器或浏览器运行,则需要在 NearbyDevicesViewController 中进行手动配置。

当服务器通过MCNearbyServiceAdvertiserDelegate 获得邀请时,广告客户崩溃,以下异常

Visual Studio 输出

Launched application 'net.agent7.AELP-MP' on '73' with pid 677
Loaded assembly: /private/var/containers/Bundle/Application/D2774A07-619E-44C5-9137-526686F6769C/AELPMP.app/Xamarin.iOS.dll [External]
Thread started:  #2
Loaded assembly: /private/var/containers/Bundle/Application/D2774A07-619E-44C5-9137-526686F6769C/AELPMP.app/System.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D2774A07-619E-44C5-9137-526686F6769C/AELPMP.app/AELPMP.exe
Resolved pending breakpoint at 'ChatSessionDelegate.cs:18,1' to void AELPMP.ChatSessionDelegate.DidChangeState (MultipeerConnectivity.MCSession session, MultipeerConnectivity.MCPeerID peerID, MultipeerConnectivity.MCSessionState state) [0x00001].
Resolved pending breakpoint at 'ChatSessionDelegate.cs:25,46' to void AELPMP.ChatSessionDelegate.DidChangeState (MultipeerConnectivity.MCSession session, MultipeerConnectivity.MCPeerID peerID, MultipeerConnectivity.MCSessionState state) [0x00069].
Resolved pending breakpoint at 'MyNearbyAdvertiserDelegate.cs:18,1' to void AELPMP.MyNearbyAdvertiserDelegate.DidReceiveInvitationFromPeer (MultipeerConnectivity.MCNearbyServiceAdvertiser advertiser, MultipeerConnectivity.MCPeerID peerID, Foundation.NSData context, MultipeerConnectivity.MCNearbyServiceAdvertiserInvitationHandler invitationHandler) [0x00000].
Resolved pending breakpoint at 'MyNearbyAdvertiserDelegate.cs:14,1' to void AELPMP.MyNearbyAdvertiserDelegate..ctor (AELPMP.NearbyDevicesViewController session) [0x00008].
Starting advertising...
2018-03-14 17:14:35.852 AELPMP[677:249758] critical: Stacktrace:

2018-03-14 17:14:35.852 AELPMP[677:249758] critical:   at <unknown> <0xffffffff>
2018-03-14 17:14:35.853 AELPMP[677:249758] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x00007>
2018-03-14 17:14:35.854 AELPMP[677:249758] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.0.15/src/Xamarin.iOS/UIKit/UIApplication.cs:79
2018-03-14 17:14:35.855 AELPMP[677:249758] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.0.15/src/Xamarin.iOS/UIKit/UIApplication.cs:63
2018-03-14 17:14:35.855 AELPMP[677:249758] critical:   at AELPMP.Application.Main (string[]) [0x00001] in /Users/lamont/Downloads/AELPMP/Main.cs:12
2018-03-14 17:14:35.856 AELPMP[677:249758] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) [0x0001e] in <0a8ff55fca4d4370bf8503724a39a15f#C25D3657-4A8E-C9A0-B325-6976392E2CBB>:0
2018-03-14 17:14:35.857 AELPMP[677:249758] critical: 
Native stacktrace:

2018-03-14 17:14:35.891 AELPMP[677:249758] critical:    0   libmonosgen-2.0.dylib               0x0000000101200664 mono_handle_native_crash + 224
2018-03-14 17:14:35.892 AELPMP[677:249758] critical:    1   libmonosgen-2.0.dylib               0x000000010120d394 mono_sigsegv_signal_handler + 316
2018-03-14 17:14:35.892 AELPMP[677:249758] critical:    2   libsystem_platform.dylib            0x0000000185d73b50 _sigtramp + 52
2018-03-14 17:14:35.892 AELPMP[677:249758] critical:    3   libxamarin-debug.dylib              0x0000000101519f94 xamarin_get_block_wrapper_creator + 52
2018-03-14 17:14:35.892 AELPMP[677:249758] critical:    4   libxamarin-debug.dylib              0x000000010151dbd8 _ZL32get_method_block_wrapper_creatorP11_MonoMethodiPj + 260
2018-03-14 17:14:35.892 AELPMP[677:249758] critical:    5   libxamarin-debug.dylib              0x000000010151da04 xamarin_get_delegate_for_block_parameter + 64
2018-03-14 17:14:35.893 AELPMP[677:249758] critical:    6   AELPMP                              0x0000000100ba55f0 _ZL30native_to_managed_trampoline_8P11objc_objectP13objc_selectorPP11_MonoMethodP25MCNearbyServiceAdvertiserP8MCPeerIDP6NSDataS0_j + 848
2018-03-14 17:14:35.893 AELPMP[677:249758] critical:    7   AELPMP                              0x0000000100ba5294 -[AELPMP_MyNearbyAdvertiserDelegate advertiser:didReceiveInvitationFromPeer:withContext:invitationHandler:] + 80
2018-03-14 17:14:35.893 AELPMP[677:249758] critical:    8   MultipeerConnectivity               0x00000001a2080934 <redacted> + 180
2018-03-14 17:14:35.893 AELPMP[677:249758] critical:    9   libdispatch.dylib                   0x0000000185acea54 <redacted> + 24
2018-03-14 17:14:35.893 AELPMP[677:249758] critical:    10  libdispatch.dylib                   0x0000000185acea14 <redacted> + 16
2018-03-14 17:14:35.894 AELPMP[677:249758] critical:    11  libdispatch.dylib                   0x0000000185adb698 <redacted> + 1016
2018-03-14 17:14:35.894 AELPMP[677:249758] critical:    12  CoreFoundation                      0x00000001860f7344 <redacted> + 12
2018-03-14 17:14:35.894 AELPMP[677:249758] critical:    13  CoreFoundation                      0x00000001860f4f20 <redacted> + 2012
2018-03-14 17:14:35.894 AELPMP[677:249758] critical:    14  CoreFoundation                      0x0000000186014c58 CFRunLoopRunSpecific + 436
2018-03-14 17:14:35.895 AELPMP[677:249758] critical:    15  GraphicsServices                    0x0000000187ec0f84 GSEventRunModal + 100
2018-03-14 17:14:35.895 AELPMP[677:249758] critical:    16  UIKit                               0x000000018f76d5c4 UIApplicationMain + 236
2018-03-14 17:14:35.895 AELPMP[677:249758] critical:    17  libXamarin.iOS.dll.dylib            0x000000010112fce0 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 368
2018-03-14 17:14:35.895 AELPMP[677:249758] critical:    18  libXamarin.iOS.dll.dylib            0x000000010111a1bc UIKit_UIApplication_Main_string___intptr_intptr + 44
2018-03-14 17:14:35.896 AELPMP[677:249758] critical:    19  libXamarin.iOS.dll.dylib            0x000000010111a17c UIKit_UIApplication_Main_string___string_string + 172
2018-03-14 17:14:35.896 AELPMP[677:249758] critical:    20  libAELPMP.exe.dylib                 0x0000000100bcbf80 AELPMP_Application_Main_string__ + 128
2018-03-14 17:14:35.896 AELPMP[677:249758] critical:    21  libmscorlib.dll.dylib               0x0000000100dcb8e8 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 248
2018-03-14 17:14:35.896 AELPMP[677:249758] critical:    22  libmonosgen-2.0.dylib               0x00000001012104e0 mono_jit_runtime_invoke + 968
2018-03-14 17:14:35.897 AELPMP[677:249758] critical:    23  libmonosgen-2.0.dylib               0x0000000101290620 do_runtime_invoke + 112
2018-03-14 17:14:35.897 AELPMP[677:249758] critical:    24  libmonosgen-2.0.dylib               0x00000001012939b0 do_exec_main_checked + 144
2018-03-14 17:14:35.897 AELPMP[677:249758] critical:    25  libmonosgen-2.0.dylib               0x00000001011f2274 mono_jit_exec + 268
2018-03-14 17:14:35.897 AELPMP[677:249758] critical:    26  libxamarin-debug.dylib              0x000000010152ccd0 xamarin_main + 2220
2018-03-14 17:14:35.897 AELPMP[677:249758] critical:    27  AELPMP                              0x0000000100ba9958 main + 96
2018-03-14 17:14:35.898 AELPMP[677:249758] critical:    28  libdyld.dylib                       0x0000000185b3456c <redacted> + 4
2018-03-14 17:14:35.898 AELPMP[677:249758] critical: 
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

XCode 输出 这是我通过 Xcode 连接并查看设备日志时的输出

Incident Identifier: 791E1B33-A22E-4684-8ADF-0E4F601E01FC
CrashReporter Key:   8168b2a05f10e5f21da37250e7a61b844de00385
Hardware Model:      iPhone9,1
Process:             AELPMP [263]
Path:                /private/var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/AELPMP
Identifier:          net.agent7.AELP-MP
Version:             1.0 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           net.agent7.AELP-MP [413]


Date/Time:           2018-03-13 20:17:17.5692 -0400
Launch Time:         2018-03-13 20:17:17.4649 -0400
OS Version:          iPhone OS 11.2.6 (15D100)
Baseband Version:    3.42.00
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Description: DYLD, Library not loaded: @rpath/libmonosgen-2.0.dylib | Referenced from: /var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/AELPMP | Reason: no suitable image found.  Did find: | /private/var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/libmonosgen-2.0.dylib: required code signature missing for '/private/var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/libmonosgen-2.0.dylib' | 
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 Crashed:
0   dyld                            0x000000010066ef48 __abort_with_payload + 8
1   dyld                            0x000000010066e71c abort_with_payload_wrapper_internal + 100
2   dyld                            0x000000010066e748 fcntl + 0
3   dyld                            0x0000000100644498 dyld::fastBindLazySymbol+ 17560 (ImageLoader**, unsigned long) + 0
4   dyld                            0x0000000100647714 dyld::_main+ 30484 (macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 7376
5   dyld                            0x000000010064121c _dyld_start + 68

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000006   x1: 0x0000000000000005   x2: 0x000000016f92e4b0   x3: 0x000000000000008b
    x4: 0x000000016f92e0b0   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x00000000000002e0
    x8: 0x0000000000000020   x9: 0x0000000000000009  x10: 0x67736f6e6f6d6269  x11: 0x642e302e322d6e65
   x12: 0x2f7070612e504d50  x13: 0x736f6e6f6d62696c  x14: 0x2e302e322d6e6567  x15: 0x000a2762696c7964
   x16: 0x0000000000000209  x17: 0x000000008000001f  x18: 0xfffffff00f0dd260  x19: 0x0000000000000000
   x20: 0x000000016f92e0b0  x21: 0x000000000000008b  x22: 0x000000016f92e4b0  x23: 0x0000000000000005
   x24: 0x0000000000000006  x25: 0x00000001004d0000  x26: 0x0000000100682000  x27: 0x0000000100681f88
   x28: 0x000000016f92fab0   fp: 0x000000016f92e080   lr: 0x000000010066e71c
    sp: 0x000000016f92e040   pc: 0x000000010066ef48 cpsr: 0x00000000

Binary Images:
0x1004d0000 - 0x1004dffff AELPMP arm64  <cf358776c3b038b6b2ba40f0fce56323> /var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/AELPMP
0x100500000 - 0x10050ffff libAELPMP.exe.dylib arm64  <125e771584d2332084c3901961cd3b59> /var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/libAELPMP.exe.dylib
0x100524000 - 0x10052bfff libSystem.dll.dylib arm64  <e2f273739ebe391f961f97cb8573fdde> /var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/libSystem.dll.dylib
0x100640000 - 0x10067ffff dyld arm64  <477a8a1f098b3a80860d656a3f4918ea> /usr/lib/dyld
0x1006dc000 - 0x100857fff libmscorlib.dll.dylib arm64  <141d1723f765324bb687d89b93133a2b> /var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/libmscorlib.dll.dylib
0x100b38000 - 0x100b9bfff libXamarin.iOS.dll.dylib arm64  <c208d3645de53ba59a7ff7179ff584bb> /var/containers/Bundle/Application/99083856-91ED-46FF-A844-2E30F49014FF/AELPMP.app/libXamarin.iOS.dll.dylib

EOF

【问题讨论】:

那么......我们是否应该浏览整个代码库以查看一个版本和另一个版本之间的不同之处?请发帖minimal reproducible example @CamiloTerevinto 链接的工作code only approach 是一个最小的完整可验证示例(对吗?)。我尝试简单地移植失败的服务器。我希望通过某种方式来更多地了解 iOS 输出。 @CamiloTerevinto 因为这需要两个节点(服务器和客户端),您还建议我如何创建这样的示例? 要么发布 C# 异常/堆栈跟踪,要么使用构建中的 msym 符号化原生 iOS 崩溃。 @SushiHangover 我想我确实从问题的第一个版本到当前版本发布了 C# 异常。如果需要更多的工作,我会做的。不知道如何处理 iOS 崩溃 【参考方案1】:

在类似的情况下,我发现在再次构建之前删除输出文件夹并清理可以解决此问题。

右键单击解决方案并选择“删除输出文件夹”

【讨论】:

以上是关于Xamarin:libmonosgen-2.0.dylib:MCNearbyServiceAdvertiser 上缺少必需的代码签名的主要内容,如果未能解决你的问题,请参考以下文章

Xamarin.forms(或)xamarin.ios/xamarin.android(或)本机

Xamarin挖墙脚系列:Xamarin的核心

Xamarin.Forms 和 Xamarin Native 有啥区别? [关闭]

Xamarin SQLite教程Xamarin.iOS项目添加引用

新的 Xamarin 项目不使用最新的 Xamarin 版本

当 Xamarin.ios Uitest 从 Xamarin Studio 运行时,在 Xamarin 测试云上面临“停滞的错误”