我正在从a working code-only approach使用MultiPeer框架并将其移至into a MVVM structure,并在下面遇到异常。
我在两台不同的计算机上使用Mac OS High Sierra,每台计算机都配有iPhone running my MVVM instance.
我仔细检查了纯代码方法,甚至在实例中使用属性(而不是字段)。这似乎是Xamarin绑定或链接器问题。
NeighborhoodDevicesViewController.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
最佳答案
在类似情况下,我发现删除输出文件夹并在再次构建之前进行清理可以解决此问题。
右键单击解决方案,然后选择“删除输出文件夹”
关于c# - Xamarin:libmonosgen-2.0.dylib:MCNearbyServiceAdvertiser上缺少必需的代码签名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49288121/