monogame content load file not found exception - c#

The following post looks similar to my issue, but ultimately it doesn't look exactly the same down to all the details, so I am calling that out to prevent claims that its the same.
I am following this monogame tutorial (currently on step 2) in Xamarin Studio:
When I run the resulting monogame app at the end of step 2 I get the following exception (pasted at the end) when I hit the line of code that attempts to load the player content. I have the player content file setup correctly AFAIK, its copied to the output folder, but I am assuming that its somehow not deployed correctly to the Andriod Virtual Machine (AVM), which I have not been able to figure out how to examine the deployed contents. I pulled up Android Monitor to explore the AVM and try to figure out where things are, but I haven't had any luck figuring that out... The file not found exception seems to be clear that what's running on the AVM isn't finding the content file... but I can't figure out how to correct that.
Any help would be appreciated, thanks!
The sources and project that I am having this issue with are here
The exception I am seeing is the following:
[MonoDroid] UNHANDLED EXCEPTION: Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Graphics\player asset as a non-content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: Opening stream error. ---> Java.IO.FileNotFoundException: Exception of type 'Java.IO.FileNotFoundException' was thrown. [MonoDroid] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0 [MonoDroid] at Android.Content.Res.AssetManager.Open (System.String fileName) [0x00000] in :0 [MonoDroid] at Microsoft.Xna.Framework.TitleContainer.OpenStream (System.String name) [0x00000] in :0 [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [MonoDroid] --- End of managed exception stack trace --- [MonoDroid] java.io.FileNotFoundException: Content/Graphics/player.xnb [MonoDroid] at android.content.res.AssetManager.openAsset(Native Method) [MonoDroid] at android.content.res.AssetManager.open(AssetManager.java:315) [MonoDroid] at android.content.res.AssetManager.open(AssetManager.java:289) [MonoDroid] at mono.java.lang.RunnableImplementor.n_run(Native Method) [MonoDroid] at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29) [MonoDroid] at android.os.Handler.handleCallback(Handler.java:605) [MonoDroid] at android.os.Handler.dispatchMessage(Handler.java:92) [MonoDroid] at android.os.Looper.loop(Looper.java:137) [MonoDroid] at android.app.ActivityThread.main(ActivityThread.java:4424) [MonoDroid] at java.lang.reflect.Method.invokeNative(Native Method) [MonoDroid] at java.lang.reflect.Method.invoke(Method.java:511) [MonoDroid] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) [MonoDroid] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) [MonoDroid] at dalvik.system.NativeStart.main(Native Method) [MonoDroid] [MonoDroid] --- End of inner exception stack trace --- [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[Texture2D] (System.String assetName, System.Action1 recordDisposableObject) [0x00000] in :0
[MonoDroid] --- End of inner exception stack trace ---
[MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset (string,System.Action1) <0x0042c> [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.Load (string) <0x000c3> [MonoDroid] at SampleShooter.Game1.LoadContent () <0x0018b> [MonoDroid] at Microsoft.Xna.Framework.Game.Initialize () <0x0023f> [MonoDroid] at SampleShooter.Game1.Initialize () <0x00037> [MonoDroid] at Microsoft.Xna.Framework.Game.DoInitialize () <0x00037> [MonoDroid] at Microsoft.Xna.Framework.AndroidGamePlatform.BeforeUpdate (Microsoft.Xna.Framework.GameTime) <0x0002b> [MonoDroid] at Microsoft.Xna.Framework.Game.DoUpdate (Microsoft.Xna.Framework.GameTime) <0x0002f> [MonoDroid] at Microsoft.Xna.Framework.Game.Tick () <0x00493> [MonoDroid] at Microsoft.Xna.Framework.AndroidGameWindow.OnUpdateFrame (OpenTK.FrameEventArgs) <0x000a7> [MonoDroid] at OpenTK.Platform.Android.AndroidGameView.UpdateFrameInternal (OpenTK.FrameEventArgs) <0x00033> [MonoDroid] at OpenTK.Platform.Android.AndroidGameView.RunIteration (System.Threading.CancellationToken) <0x001c3> [MonoDroid] at OpenTK.Platform.Android.AndroidGameView/c__AnonStorey0.<>m__2 (object) <0x00027> [MonoDroid] at Android.App.SyncContext/c__AnonStorey2F.<>m__1A () <0x00023> [MonoDroid] at Java.Lang.Thread/RunnableImplementor.Run () <0x0003f> [MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x00037> [MonoDroid] at (wrapper dynamic-method) object.e85befee-f4e0-4f15-9232-77621081c7b5 (intptr,intptr) <0x0003b> [mono] [mono] Unhandled Exception: [mono] Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Graphics\player asset as a non-content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: Opening stream error. ---> Java.IO.FileNotFoundException: Exception of type 'Java.IO.FileNotFoundException' was thrown. [mono] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0 [mono] at Android.Content.Res.AssetManager.Open (System.String fileName) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.TitleContainer.OpenStream (System.String name) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [mono] --- End of managed exception stack trace --- [mono] java.io.FileNotFoundException: Content/Graphics/player.xnb [mono] at android.content.res.AssetManager.openAsset(Native Method) [mono] at android.content.res.AssetManager.open(AssetManager.ja [mono] [ERROR] FATAL UNHANDLED EXCEPTION: Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Graphics\player asset as a non-content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: Opening stream error. ---> Java.IO.FileNotFoundException: Exception of type 'Java.IO.FileNotFoundException' was thrown. [mono] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0 [mono] at Android.Content.Res.AssetManager.Open (System.String fileName) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.TitleContainer.OpenStream (System.String name) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [mono] --- End of managed exception stack trace --- [mono] java.io.FileNotFoundException: Content/Graphics/player.xnb [mono] at android.content.res.AssetManager.openAsset(Native Method) [mono] at android.content.res.AssetManager.open(As

So I finally figured out that I needed to mark the XNB file as an AndroidAsset for the build action, and not Content as the example stated. Since the example I am following is aimed at Windows Mobile development this makes sense since the file would normally be marked as content for a Windows application, whereas for Android these files need to be marked as AndriodAsset in order for XNA to be able to access the raw content data, regardless of if the file is in a content or asset folder. The content manager's root folder by default is "Content", so you need to add the file there and mark it as an asset, not content...

Content for an android monogame project should be added to the project in the Assets/Content folder as built .xnb files rather than just copied to the output directory

Related

UNHANDLED EXCEPTION: System.ArgumentException: element must be of type Button (Xamarin.Forms - Android)

I'm getting this exception after updating Xamarin.Forms to version 4.7.0.968
Stack trace:
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.ArgumentException: element must be of type Button
[MonoDroid] at Xamarin.Forms.Platform.Android.RadioButtonRenderer.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00016] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\RadioButtonRenderer.cs:102
[MonoDroid] at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:350
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x000b3] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:140
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00163] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:351
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:112
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:465
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000d5] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:245
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:135
[MonoDroid] at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in D:\a\1\s\Xamarin.Forms.Platform.Android\Platform.cs:350
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x000b3] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:140
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:112
[MonoDroi10-16 12:32:01.021 I] at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:465
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000d5] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:245
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00033] in D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:135
[MonoDroid] at Xamarin.Forms.Platform.Android.ViewCellRenderer.GetCellCore (Xamarin.Forms.Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context) [0x000a4] in D:\a\1\s\Xamarin.Forms.Platform.Android\Cells\ViewCellRenderer.cs:44
[MonoDroid] at Xamarin.Forms.Platform.Android.CellRenderer.GetCell (Xamarin.Forms.Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context) [0x00075] in D:\a\1\s\Xamarin.Forms.Platform.Android\Cells\CellRenderer.cs:51
[MonoDroid] at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00163] in D:\a\1\s\Xamarin.Forparent, Android.Content.Context context, Xamarin.Forms.View view) [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.Android\Cells\CellFactory.cs:20
[MonoDroid] at Xamarin.Forms.Platform.Android.ListViewAdapter.GetView (System.Int32 position, Android.Views.View convertView, Android.Views.ViewGroup parent) [0x00211] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ListViewAdapter.cs:304
[MonoDroid] at Android.Widget.BaseAdapter.n_GetView_ILandroid_view_View_Landroid_view_ViewGroup_ (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position, System.IntPtr native_convertView, System.IntPtr native_parent) [0x00019] in /Users/builder/azdo/_work/287/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Widget.BaseAdapter.cs:521
[MonoDroid] at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.124(intptr,intptr,int,intptr,intptr)
[Mono] Probing 'java_interop_jnienv_throw'.
[Mono] Found as 'java_interop_jnienv_throw'.
I have reported bug on GitHub: Check Bug
Anyone know how to handle this exception or fix this issue?
Are you using Custom renderer for the Radio button? It might be an issue
Thanks to #GeraldVersluis for the answer to the bug I have reported on GitHub I have got the solution. Here is the solution:
Ah, you are not using the built-in RadioButton at all? You have created your own? It might be some naming conflict. I would rename the RadioButtonRenderer to CustomRadioButtonRenderer and see if that works better. This is because of Xamarin.Forms have a RadioButton now too.
Then I have just changed my Renderer name as he suggested to CustomRadioButtonRenderer and it's started working fine after that.

Xamarin camera2 api is in background not working

I am interested in Xamarin and I search, how I can take a photo from camera without device's native camera application. And I found Camera2 API, then I search sample app and I found this sample app: https://learn.microsoft.com/en-us/samples/xamarin/monodroid-samples/android50-camera2basic/
It worked very well when I tried it in the foreground but it gives an error when I put it in the background.
How can I get it running in the background?
Camera2BasicFragment.cs codes: https://paste.ubuntu.com/p/CqDkyMx8qW/
Exceptions:
Exception image 1
Exception image 2
Exception Text:
{Java.Lang.IllegalStateException: CameraDevice was already closed at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00014] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0 at Android.Hardware.Camera2.CameraCaptureSessionInvoker.Capture (Android.Hardware.Camera2.CaptureRequest request, Android.Hardware.Camera2.CameraCaptureSession+CaptureCallback listener, Android.OS.Handler handler) [0x0006e] in /Users/builder/azdo/_work/204/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-27/mcw/Android.Hardware.Camera2.CameraCaptureSession.cs:969 at Camera2Basic.Camera2BasicFragment.LockFocus () [0x00020] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:576 at Camera2Basic.Camera2BasicFragment.TakePicture () [0x00001] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:563 at Camera2Basic.Camera2BasicFragment.OnClick (Android.Views.View v) [0x00013] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:676 at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/builder/azdo/_work/204/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-27/mcw/Android.Views.View.cs:2176 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.19(intptr,intptr,intptr) --- End of managed Java.Lang.IllegalStateException stack trace ---java.lang.IllegalStateException: CameraDevice was already closed at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1997) at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:844) at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:741) at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:179) at crc64b678081366886b9e.Camera2BasicFragment.n_onClick(Native Method) at crc64b678081366886b9e.Camera2BasicFragment.onClick(Camera2BasicFragment.java:77) at android.view.View.performClick(View.java:5721) at android.widget.TextView.performClick(TextView.java:10936) 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:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)}

Mono compiler // Terminal emulator issue

I get this error when I try to compile csharp or fsharp files. This happens when using gnome terminal or jetbrain rider.
It works fine in tty or termials like xterm and urxvt.
Also I am able to compile c, c++ and go code.
Btw, I am using Arch/Antergos and got this issue yesterday.
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 :0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in :0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in :0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in :0
at System.ConsoleDriver..cctor () [0x0004d] in :0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in :0
at System.Console..cctor () [0x0008e] in :0
--- End of inner exception stack trace ---
at Mono.CSharp.Driver.Main (System.String[] args) [0x00019] in <2b1e99ce45b54209bdcdab138d9758ae>: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 :0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in :0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in :0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in :0
at System.ConsoleDriver..cctor () [0x0004d] in :0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding) [0x00007] in :0
at System.Console..cctor () [0x0008e] in :0
--- End of inner exception stack trace ---
at Mono.CSharp.Driver.Main (System.String[] args) [0x00019] in <2b1e99ce45b54209bdcdab138d9758ae>:0

Realm Xamarin - Error on GetInstance()

I set my main page in this way:
namespace MyNamepage
{
public partial class MyPage: ContentPage
{
private Realm realm;
public MyPage()
{
InitializeComponent();
this.realm = Realm.GetInstance();
}
}
}
Debugging the Android project i got this error and the app crash:
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation.
I've installed "Realm" in PCL and in Droid Project using NuGet but it seems doesn't work.
If i remove the GetInstance() call, the app doesn't crash;
Stack trace:
10-17 10:36:31.935 I/MonoDroid(31518): UNHANDLED EXCEPTION:
10-17 10:36:31.955 I/MonoDroid(31518): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:31.955 I/MonoDroid(31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:31.955 I/MonoDroid(31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:31.955 I/MonoDroid(31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:31.955 I/MonoDroid(31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:31.955 I/MonoDroid(31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:31.965 I/MonoDroid(31518): --- End of inner exception stack trace ---
10-17 10:36:31.965 I/MonoDroid(31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00016] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:650
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceMono (Boolean nonPublic) [0x000ca] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:115
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceSlow (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x0001a] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:89
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceDefaultCtor (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x0002a] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/rttype.cs:5599
10-17 10:36:31.965 I/MonoDroid(31518): at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00040] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/activator.cs:201
10-17 10:36:31.965 I/MonoDroid(31518): at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/activator.cs:134
10-17 10:36:31.965 I/MonoDroid(31518): at MyPack.MainPage.OnItemSelected (System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e) [0x00016] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\MainPage.xaml.cs:24
10-17 10:36:31.965 I/MonoDroid(31518): at (wrapper delegate-invoke) System.EventHandler`1[Xamarin.Forms.SelectedItemChangedEventArgs]:invoke_void_object_TEventArgs (object,Xamarin.Forms.SelectedItemChangedEventArgs)
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.OnSelectedItemChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x0001c] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes) [0x00000] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.NotifyRowTapped (Int32 groupIndex, Int32 inGroupIndex, Xamarin.Forms.Cell cell) [0x0004c] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.NotifyRowTapped (Int32 index, Xamarin.Forms.Cell cell) [0x00023] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.Platform.Android.ListViewAdapter.HandleItemClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x00056] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.Platform.Android.CellAdapter.OnItemClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x0002e] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Android.Widget.AdapterView+IOnItemClickListenerInvoker.n_OnItemClick_Landroid_widget_AdapterView_Landroid_view_View_IJ (IntPtr jnienv, IntPtr native__this, IntPtr native_parent, IntPtr native_view, Int32 position, Int64 id) [0x00019] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Widget.AdapterView.cs:215
10-17 10:36:31.975 I/MonoDroid(31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:31.995 D/Mono (31518): DllImport searching in: '__Internal' ('(null)').
10-17 10:36:31.995 D/Mono (31518): Searching for 'java_interop_jnienv_throw'.
10-17 10:36:31.995 D/Mono (31518): Probing 'java_interop_jnienv_throw'.
10-17 10:36:31.995 D/Mono (31518): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.
10-17 10:36:34.115 E/mono (31518):
10-17 10:36:34.115 E/mono (31518): Unhandled Exception:
10-17 10:36:34.115 E/mono (31518): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:34.115 E/mono (31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono (31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono (31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:34.115 E/mono (31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:34.115 E/mono (31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:34.115 E/mono (31518): --- End of inner exception stack trace ---
10-17 10:36:34.115 E/mono (31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono (31518): at (wrapper native-to-managed) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono-rt (31518): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:34.115 E/mono-rt (31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono-rt (31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono-rt (31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:34.115 E/mono-rt (31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:34.115 E/mono-rt (31518): --- End of inner exception stack trace ---
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper native-to-managed) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
In mgmain JNI_OnLoad
As the stack trace indicates and the path you have posted in the comments shows. You have installed the PCL version into the platform specific projects. Which is why it throws the PlatformNotSupportedException exception you are getting.
Try reinstalling the NuGet in your platform specific projects. Alternatively you can manually change the reference to point at:
packages\Realm.0.78.1\lib\MonoAndroid44\Realm.dll
You shouldn't have any reference to the portable folder in your platform specific project.
I had a similar problem using Xamarin.Forms 3.4.0.1008975 with Realm 4.0.1
Unhandled Exception: System.TypeInitializationException: The type
initializer for 'Realms.SharedRealmHandle' threw an exception.
occurred
The solution was to completely uninstall the nuget Realm package from all projects in the solution and reinstall Realm back again. Also make sure that you have the FodyWeaver.xml file in all projects.

Missing method exception when referencing Google Maps class

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.

Categories

Resources