we are programming an multiplatform program with mono.
now i want to use some native code on a mac.
I found the NSLocal class and wanted to use:
string test = NSLocale.CurrentLocale.CountryCode;
but i run into an exception when the program is hitting this code:
Message: An exception of Type System.ArgumentNullException occured.
Message was: Value cannot be null. Parameter name: obj
Stacktrace:
at (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_monitor_enter_v4_internal
(object,intptr) at ObjCRuntime.Runtime.TryGetNSObject (System.IntPtr
ptr, System.Boolean evenInFinalizerQueue) [0x00009] in
<1a80b695c02b4e7dbda63e331ae0ac27>:0
other code like:
string[] test2 = NSLocale.ISOCountryCodes;
also runs into an exception:
Message: An exception of type System.TypeInitializationException
occured. Message was: The type initializer for 'Foundation.NSString'
threw an exception.
Stacktrace:
at Foundation.NSArray.StringArrayFromHandle (System.IntPtr handle)
[0x00047] in <1a80b695c02b4e7dbda63e331ae0ac27>:0 at
Foundation.NSLocale.get_ISOCountryCodes() [0x00010] in
<1a80b695c02b4e7dbda63e331ae0ac27>:0
well what i'am doing wrong? when i'm calling this native code?
Thanks
Related
I am using Xamarin Android Native to create a worker handler using postdelay to run some background data fetching from webservice, the handler would call a function every few seconds, but when the activity runs, the app crashes randomly, and the FATAL EXCEPTION stack trace did not specify where exactly the problem is and every time it just throw the same message: "android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Java.Lang.Thread+RunnableImplementor from native handle"
Following is the detail stack-trace:
AndroidRuntime: FATAL EXCEPTION: main
Process: ..., PID: 23551
android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Java.Lang.Thread+RunnableImplementor from native handle 0xffd76a6c (key_handle 0x5005665). ---> System.MissingMethodException: No constructor found for Java.Lang.Thread+RunnableImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00054] in <263adecfa58f4c449f1ff56156d886fd>:0
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00111] in <263adecfa58f4c449f1ff56156d886fd>:0
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x0017d] in <263adecfa58f4c449f1ff56156d886fd>:0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000b9] in <263adecfa58f4c449f1ff56156d886fd>:0
at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in <263adecfa58f4c449f1ff56156d886fd>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <263adecfa58f4c449f1ff56156d886fd>:0
at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <263adecfa58f4c449f1ff56156d886fd>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in <263adecfa58f4c449f1ff56156d886fd>:0
at (wrapper dynamic-method) System.Object.eac9d564-b7f8-4035-a2ff-b38fdb337e7b(intptr,intptr)
at mono.java.lang.RunnableImplementor.n_run(Native Method)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at android.os.Handler.handleCallback(Handler.java:794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
Who has encounter the same before?
And how to resolve this issue?
Your help is so much appreciated.
Occasionally the following line throws a System.OverflowException:
var request = new RestRequest("", Method.GET, DataFormat.Json);
This is running on a Raspbian OS using the Mono Runtime.
The Exception never happened on Windows where the application was developed.
Full Stacktrace:
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'RestSharp.RestRequest' threw an exception. --->
System.TypeInitializationException: The type initializer for 'System.Text.RegularExpressions.Regex' threw an exception. --->
System.OverflowException: TimeSpan overflowed because the duration is too long.
at System.TimeSpan.Interval (System.Double value, System.Int32 scale) <0xb4a01520 + 0x0010c> in <d0a5e45894084fd7b6ea7e0fe6ac414c>:0
at System.TimeSpan.FromMilliseconds (System.Double value) <0xb4a0165c + 0x0001b> in <d0a5e45894084fd7b6ea7e0fe6ac414c>:0
at System.Text.RegularExpressions.Regex..cctor () [0x0001c] in <c0e40d34c25e4827874530676d4126b9>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at RestSharp.RestRequest..cctor () [0x00000] in <bc58aa49caeb486c80c16d44db0069c3>:0
I am trying to compile a C# Hello World application in Rider on Linux.
When I try to run the app, I am promted the following exception:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver..cctor () [0x0004d] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.Console..cctor () [0x0008e] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at TestCaseApp.Program.Main (System.String[] args) [0x00001] in <662667bfa1e4443ea031df076247d2d3>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver..cctor () [0x0004d] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.Console..cctor () [0x0008e] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at TestCaseApp.Program.Main (System.String[] args) [0x00001] in <662667bfa1e4443ea031df076247d2d3>:0
I am using Antergos (Linux) and JetBrains Rider 2017.3.1
Build #RD-173.3994.2442
I have am using Mono 5.4.1.7-2
I did some research about this bug and I found:
https://github.com/mono/mono/issues/6752#issuecomment-365212655
Mono compiler // Terminal emulator issue
Everything mentioned in these threads didn't help me to fix this issue. What can I do?
Did you not follow the instructions on that page? You need to set your TERM environmental variable to xterm as a fix:
export TERM=xterm
Then verify it is changed with:
echo $TERM
The means exactly this: "I want to run your script, but you need to specify the terminal you want me to use"
In GoG version of Stardew Valley, the script in question is: ./start.sh
Launching this causes the above error.
If instead:
export 'TERM=roxterm' && ./start.sh
then it works because I have the roxterm terminal installed on my system and the script can use it to execute. What I do know is the global parameter in Ubuntu that tells scrips use this unless it is: Default Applications
Looking at snippet of the script, originally it is:
run_game() {
echo "Running ${GAME_NAME}"
cd game
chmod +x *
./"StardewValley"
}
Corrected for roxterm it would be:
run_game() {
echo "Running ${GAME_NAME}"
cd game
chmod +x *
export 'TERM=roxterm' && ./"StardewValley"
}
The latter solution works with application launchers and is thus superior.
I am writing a plugin manager for my android app written in Xamarin with MvvmCross.
I am loading the assembly just fine, i can enumerate all types (ViewModels, Views, ...). For the view type finding, i implemented a custom IMvxViewFinder that i registered during Setup
protected override IMvxAndroidViewsContainer CreateViewsContainer(Context applicationContext)
{
var androidViewsContainer = base.CreateViewsContainer(applicationContext);
var viewsContainer = androidViewsContainer as IMvxViewsContainer;
if (viewsContainer != null)
{
viewsContainer.AddSecondary(new PluginViewFinder());
}
return androidViewsContainer;
}
I am able to match the external viewmodel to the external view type. All functions are hit and the correct views are returned. But I still get a class not found exception
Java.Lang.ClassNotFoundException: Didn't find class "md5996393b23f6d276fda35c7846aecfb34.FirstView" on path: DexPathList[[zip file "/data/app/test.droid-1/base.apk"],nativeLibraryDirectories=[/data/app/test.droid-1/lib/arm, /vendor/lib, /system/lib]]
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0
at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00064] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:195
at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x0001d] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:203
at Android.Runtime.JNIEnv.FindClass (System.String classname) [0x00007] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:494
at Android.Runtime.JNIEnv.FindClass (System.Type type) [0x00009] in /Users/builder/data/lanes/2098/3efa14c4/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:434
--- End of managed exception stack trace ---
java.lang.ClassNotFoundException: Didn't find class "md5996393b23f6d276fda35c7846aecfb34.FirstView" on path: DexPathList[[zip file "/data/app/test.droid-1/base.apk"],nativeLibraryDirectories=[/data/app/test.droid-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) ...
So, it is trying to find the view inside /data/app/test.droid-1/base.apk - that's the main project, that loaded the assembly - so, for sure, the class is not in there.
Anybody a hint what i have to do for that?
I'm getting a System.MissingMethodException when I try to instantiate a Dictionary using the Android.Gms.Maps.Model.Marker class as follows:
Dictionary<Marker, MyInnerClass> _markers = new Dictionary<Marker, MyInnerClass>();
I suspect that somehow a needed dll is not being loaded but don't know why. The problem seems to be specific to my specific dev environment since other developers with the same code are not seeing this problem. I can reproduce the issue in Genymotion, an Asus Tablet and a GS4 all running Android 4.2.2.
Application output reports the following:
[] Missing method Android.Runtime.JNIEnv::AllocObject(Type) in assembly Mono.Android.dll, referenced in assembly GooglePlayServices.dll
Here's the stack trace:
System.MissingMethodException: Method not found: 'Android.Runtime.JNIEnv.AllocObject'.
at MyProduct.Maps.MyMapFragment..ctor () [0x00013] in /Users/me/code/my.domain/MyProduct/Maps/MyMapFragment.cs:48
at at (wrapper dynamic-method) object.ffa689fb-fdde-4e08-abd8-3bdf6ae641fb (intptr,object[]) <IL 0x00018, 0x00037>
at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:141
at at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <IL 0x00020, 0x0007f>
at at (wrapper managed-to-native) object.wrapper_native_0xb65e0e20 (intptr,intptr,intptr,intptr,Android.Runtime.JValue[]) <0x00003>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:612
at Android.App.Activity.SetContentView (int) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Activity.cs:3824
at MyProduct.MyListActivity.OnCreate (Android.OS.Bundle) [0x00079] in /Users/me/code/my.domain/MyProduct/MyListActivity.cs:83
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Activity.cs:1937
at at (wrapper dynamic-method) object.24a01956-09ee-4dec-9155-eff468f7249c (intptr,intptr,intptr) <IL 0x00017, 0x0001f>
Android.Runtime.JNIEnv.AllocObject() is a method that was added to Xamarin.Android 4.10.1.
It would seem that GooglePlayServices.dll was built against 4.10, while your app was packaged against 4.8 (which doesn't contain AllocObject()). This would explain the MissingMethodException.
Xamarin.Android 4.10.1 is now stable; please upgrade.