创建EventWaitHandle时可能导致NotSupportedException的原因是什么?

时间:2015-11-19 13:21:04

标签: c# android xamarin mono xamarin.android

上下文

我有一个使用Xamarin的大型跨平台项目。因为我在这个项目上独自工作,而且我们最近需要更多的WPF和Windows 10客户端,所以我完全专注于这些并忽略了Android客户端。 (是的,不要告诉我这很糟糕,我知道...... :-))

例外

然而,现在我正在再次努力,尝试启动并运行,但我在可移植类库的代码中继续获得System.NotSupportedException,其中正在创建新的EventWaitHandle

// The next line throws the System.NotSupportedException: Operation is not supported.
new EventWaitHandle(false, EventResetMode.ManualReset, module.Identifier.ToString()); // module.Identifier is a GUID (it's valid)

此代码已有几个月的历史,在WPF和Windows 10客户端中工作得很好,所以我想Xamarin Android可能不支持EventWaitHandle,但我找不到任何证据。情况恰恰相反:它是well documented

如果它有帮助(它对我帮助不大......)这里是异常的完整堆栈跟踪:

11-19 19:18:27.290 I/MonoDroid(26568): UNHANDLED EXCEPTION:
11-19 19:18:27.290 I/MonoDroid(26568): System.NotSupportedException: Operation is not supported.
11-19 19:18:27.290 I/MonoDroid(26568): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
11-19 19:18:27.290 I/MonoDroid(26568): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) <IL 0x00006, 0x0006b>
11-19 19:18:27.290 I/MonoDroid(26568): at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
11-19 19:18:27.290 I/MonoDroid(26568): at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
11-19 19:18:27.290 I/MonoDroid(26568): at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.IRunnable.cs:71
11-19 19:18:27.290 I/MonoDroid(26568): at (wrapper dynamic-method) object.c26750eb-eb85-45fe-a488-c6d12c1aaf0e (intptr,intptr) <IL 0x00011, 0x0003b>
11-19 19:18:27.315 W/art     (26568): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
11-19 19:18:27.320 D/AndroidRuntime(26568): Shutting down VM
An unhandled exception occured.

11-19 19:18:28.190 E/AndroidRuntime(26568): FATAL EXCEPTION: main
11-19 19:18:28.190 E/AndroidRuntime(26568): Process: de.msm.IDS, PID: 26568
11-19 19:18:28.190 E/AndroidRuntime(26568): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
11-19 19:18:28.190 E/AndroidRuntime(26568):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
11-19 19:18:28.190 E/AndroidRuntime(26568): Caused by: java.lang.reflect.InvocationTargetException
11-19 19:18:28.190 E/AndroidRuntime(26568):     at java.lang.reflect.Method.invoke(Native Method)
11-19 19:18:28.190 E/AndroidRuntime(26568):     at java.lang.reflect.Method.invoke(Method.java:372)
11-19 19:18:28.190 E/AndroidRuntime(26568):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
11-19 19:18:28.190 E/AndroidRuntime(26568):     ... 1 more
11-19 19:18:28.190 E/AndroidRuntime(26568): Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NotSupportedException: Operation is not supported.
11-19 19:18:28.190 E/AndroidRuntime(26568): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
11-19 19:18:28.190 E/AndroidRuntime(26568): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) <IL 0x00006, 0x0006b>
11-19 19:18:28.190 E/AndroidRuntime(26568): at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
11-19 19:18:28.190 E/AndroidRuntime(26568): at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
11-19 19:18:28.190 E/AndroidRuntime(26568): at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.IRunnable.cs:71
11-19 19:18:28.190 E/AndroidRuntime(26568): at (wrapper dynamic-method) object.c26750eb-eb85-45fe-a488-c6d12c1aaf0e (intptr,intptr) <IL 0x00011, 0x0003b>
11-19 19:18:28.190 E/AndroidRuntime(26568): 
11-19 19:18:28.190 E/AndroidRuntime(26568):     at mono.java.lang.RunnableImplementor.n_run(Native Method)
11-19 19:18:28.190 E/AndroidRuntime(26568):     at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
11-19 19:18:28.190 E/AndroidRuntime(26568):     at android.os.Handler.handleCallback(Handler.java:739)
11-19 19:18:28.190 E/AndroidRuntime(26568):     at android.os.Handler.dispatchMessage(Handler.java:95)
11-19 19:18:28.190 E/AndroidRuntime(26568):     at android.os.Looper.loop(Looper.java:145)
11-19 19:18:28.190 E/AndroidRuntime(26568):     at android.app.ActivityThread.main(ActivityThread.java:6126)
11-19 19:18:28.190 E/AndroidRuntime(26568):     ... 4 more    

项目详情

Android项目设置为使用API​​级别19:

Android project setup: using API Level 19

PCL目标包括.NET Framework 4.5和Xamarin.Android当然:

PCL targets

我主要用于调试的目标硬件设备是带有Samsung SM-P900Android 5.0.2

什么可能导致Android中的此异常(但不在Windows中)?

1 个答案:

答案 0 :(得分:1)

看看mono(Xamarin).NET实现: https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Threading/EventWaitHandle.cs

单声道不支持EventWaitHandle。

public EventWaitHandle (bool initialState, EventResetMode mode, string name)
    {
        throw new NotSupportedException ();
    }