Weird behaviour of AndroidJavaObject in Unity, when implemented through C# - unity3d

Rather long post follows. It's fairly complex, needs someone who has worked with Unity Plugins before (creating them, not using them) and I'm not looking to get downvoted because a few common search terms show up. So, please read the entire post.
So, I've been having a rather weird issue happening when I try to call native functions through Unity's AndroidJavaObject
I've built native plugins in the past before, I'm trying to remove my dependancies on having to update multiple JARs each time I need to update my plugins. So, I'm moving a lot of my native Java code from plugins, into Unity itself.
Specifically, there's a way to call native Android functions (i.e. system functions) straight from C#, rather than creating a plugin and calling a function in the plugin that invokes the native function.
For example, earlier, if I had to create a Toast, I'd have to write some native code in Java, export the plugin and then call the function. These days, one can just call the Toast.makeText straight from C# as follows.
Here's how I make the call for a Toast.
public static void Toast (string text, int duration) {
#if UNITY_ANDROID && !UNITY_EDITOR
CreateActivity();
activity.Call("runOnUiThread", new AndroidJavaRunnable ( () => {
new AndroidJavaObject("android.widget.Toast", activity)
.CallStatic<AndroidJavaObject>("makeText", activity, text, duration)
.Call("show");
}) );
#endif
}
and here's the CreateActivity method
private static void CreateActivity () {
#if UNITY_ANDROID && !UNITY_EDITOR
if(activity == null)
activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").
GetStatic<AndroidJavaObject>("currentActivity");
#endif
}
This works perfectly. However, when I try the same approach for creating an AlertDialog, I get an androidjavaexception java.lang.classnotfoundexception
Here's the relevant code
public static void ShowAlert (string title, string message, string buttonText) {
#if UNITY_ANDROID && !UNITY_EDITOR
CreateActivity();
activity.Call("runOnUiThread", new AndroidJavaRunnable ( () => {
var builder = new AndroidJavaObject("android.app.AlertDialog.Builder", activity);
***//Exception happens in the above line***
builder.Call<AndroidJavaObject>("setMessage", message)
.Call<AndroidJavaObject>("setTitle", title)
.Call<AndroidJavaObject>("setCancelable", false)
.Call<AndroidJavaObject>("setNeutralButton", buttonText)
.Call("show");
}) );
#endif
}
What I've tried
Used android.support.v7.app.AlertDialog.Builder instead of android.app.AlertDialog.Builder
Added the support JARs for v7 & v4 (Specifically android-support-v4 & android-support-v7-appcompat)
Tried creating my own implementation for Unity's JNI and invoking that
All the above failed. (The third one, rather spectacularly)
Now, I tried other classes as well, and most of them work (such as ProgressDialog, which is a subclass of AlertDialog), and those work!
At this point, I'm rather stumped and I can't think of a VALID reason for certain functions to work, and the others to fail.
Any thoughts are appreciated.
EDIT 1: Added LogCat
I/Unity: AndroidJavaException: java.lang.ClassNotFoundException: android.app.AlertDialog.Builder
at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJavaObject._CallStatic[AndroidJavaObject] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJavaObject.CallStatic[AndroidJavaObject] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJavaObject.FindClass (System.String name) [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) [0x00000] in <filename unknown>:0
at UnityEngine.AndroidJavaObject..ctor (System.String className, System.Object[] args) [0x00000] in <filename unknown>:0
at AndroidNative+<ShowAlert>c__AnonSto

The problem you are running into, is that AlertDialog.Builder is a nested class of AlertDialog, and creating nested classes through reflection (which is what AndroidJavaObject is trying to do) requires a slightly different syntax in Java:
android.app.AlertDialog$Builder
There are some other tiny mistakes in your code (that you couldn't know about because your constructor wasn't working):
setNeutralButton requires a callback argument (which can be null)
show has to be called on the AlertDialog itself, not on the builder.
Taking these tiny corrections into consideration, a working code sample looks like this:
public static void ShowAlert(string title, string message, string buttonText)
{
CreateActivity();
activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
var builder = new AndroidJavaObject("android.app.AlertDialog$Builder", activity);
builder.Call<AndroidJavaObject>("setMessage", message)
.Call<AndroidJavaObject>("setTitle", title)
.Call<AndroidJavaObject>("setCancelable", false)
.Call<AndroidJavaObject>("setNeutralButton", buttonText, null)
.Call<AndroidJavaObject>("create")
.Call("show");
}));
}

Related

Unity - DllNotFoundException: Unable to load DLL 'FirebaseCppApp-10_2_0'. on android build

I am using unity engine with firebase and I am trying to do a build for android, it does work but the firebase functions are not and I get this errors : (on the editor its working fine)
`
AndroidPlayer "samsung_SM-G988N" DllNotFoundException: Unable to load DLL 'FirebaseCppApp-10_2_0'. Tried the load the following dynamic libraries: Unable to load dynamic library 'FirebaseCppApp-10_2_0' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "FirebaseCppApp-10_2_0" not found
at Firebase.AppUtilPINVOKE+SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_AppUtil (Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate applicationDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate arithmeticDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate divideByZeroDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate indexOutOfRangeDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate invalidCastDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate invalidOperationDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate ioDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate nullReferenceDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate outOfMemoryDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate overflowDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate systemExceptionDelegate) [0x00000] in <00000000000000000000000000000000>:0
at Firebase.AppUtilPINVOKE+SWIGExceptionHelper..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.AppUtilPINVOKE..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.AppUtil.SetLogFunction (Firebase.LogUtil+LogMessageDelegate arg0) [0x00000] in <00000000000000000000000000000000>:0
at Firebase.LogUtil..ctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.LogUtil..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.FirebaseApp..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <00000000000000000000000000000000>:0
at MultiPlayerMenu.Start () [0x00000] in <00000000000000000000000000000000>:0
Rethrow as TypeInitializationException: The type initializer for 'Firebase.AppUtilPINVOKE.SWIGExceptionHelper' threw an exception.
at Firebase.AppUtilPINVOKE..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.AppUtil.SetLogFunction (Firebase.LogUtil+LogMessageDelegate arg0) [0x00000] in <00000000000000000000000000000000>:0
at Firebase.LogUtil..ctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.LogUtil..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.FirebaseApp..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <00000000000000000000000000000000>:0
at MultiPlayerMenu.Start () [0x00000] in <00000000000000000000000000000000>:0
Rethrow as TypeInitializationException: The type initializer for 'Firebase.AppUtilPINVOKE' threw an exception.
at Firebase.AppUtil.SetLogFunction (Firebase.LogUtil+LogMessageDelegate arg0) [0x00000] in <00000000000000000000000000000000>:0
at Firebase.LogUtil..ctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.LogUtil..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.FirebaseApp..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <00000000000000000000000000000000>:0
at MultiPlayerMenu.Start () [0x00000] in <00000000000000000000000000000000>:0
Rethrow as TypeInitializationException: The type initializer for 'Firebase.LogUtil' threw an exception.
at Firebase.FirebaseApp..cctor () [0x00000] in <00000000000000000000000000000000>:0
at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <00000000000000000000000000000000>:0
at MultiPlayerMenu.Start () [0x00000] in <00000000000000000000000000000000>:0
Rethrow as TypeInitializationException: The type initializer for 'Firebase.FirebaseApp' threw an exception.
at Firebase.Database.FirebaseDatabase.get_DefaultInstance () [0x00000] in <00000000000000000000000000000000>:0
at MultiPlayerMenu.Start () [0x00000] in <00000000000000000000000000000000>:0
`
For now I tried to remove unity library and it did nothing
I tried to change to IL2CPP and toggle arm64 and it did nothing
when I try android force resolve it will fail and I get this :
`
Resolution failed
Failed to fetch the following dependencies:
com.google.firebase:firebase-app-unity:+
com.google.firebase:firebase-auth-unity:+
com.google.firebase:firebase-database-unity:+
UnityEngine.Debug:LogError (object)
Google.Logger:Log (string,Google.LogLevel) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/Logger.cs:136)
GooglePlayServices.PlayServicesResolver:Log (string,Google.LogLevel) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/PlayServicesResolver.cs:1069)
GooglePlayServices.GradleResolver:LogMissingDependenciesError (System.Collections.Generic.List`1<string>) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:95)
GooglePlayServices.GradleResolver/<DoResolutionUnsafe>c__AnonStorey18:<>m__22 (System.Collections.Generic.List`1<Google.JarResolver.Dependency>) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:920)
GooglePlayServices.GradleResolver/<GradleResolution>c__AnonStorey11:<>m__17 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:383)
GooglePlayServices.GradleResolver/<GradleResolution>c__AnonStorey11:<>m__27 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:448)
GooglePlayServices.GradleResolver/<ProcessAars>c__AnonStorey1B:<>m__24 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:1123)
Google.RunOnMainThread:ExecutePollingJobs () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:409)
Google.RunOnMainThread:<ExecuteAllUnnested>m__12 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:541)
Google.RunOnMainThread:RunAction (System.Action) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
Google.RunOnMainThread:ExecuteAllUnnested (bool) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
Google.RunOnMainThread:PollOnUpdateUntilComplete (System.Func`1<bool>,bool) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:379)
GooglePlayServices.PlayServicesResolver:LabelAssets (System.Collections.Generic.IEnumerable`1<string>,System.Action`1<System.Collections.Generic.HashSet`1<string>>,bool,System.Action`2<single, string>,bool,bool) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/PlayServicesResolver.cs:2374)
GooglePlayServices.GradleResolver:ProcessAar (string) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:1425)
GooglePlayServices.GradleResolver/<ProcessAars>c__AnonStorey1B:<>m__24 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:1093)
Google.RunOnMainThread:ExecutePollingJobs () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:409)
Google.RunOnMainThread:<ExecuteAllUnnested>m__12 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:541)
Google.RunOnMainThread:RunAction (System.Action) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
Google.RunOnMainThread:ExecuteAllUnnested (bool) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
Google.RunOnMainThread:PollOnUpdateUntilComplete (System.Func`1<bool>,bool) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:379)
GooglePlayServices.PlayServicesResolver:LabelAssets (System.Collections.Generic.IEnumerable`1<string>,System.Action`1<System.Collections.Generic.HashSet`1<string>>,bool,System.Action`2<single, string>,bool,bool) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/PlayServicesResolver.cs:2374)
GooglePlayServices.GradleResolver:ProcessAar (string) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:1425)
GooglePlayServices.GradleResolver/<ProcessAars>c__AnonStorey1B:<>m__24 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/AndroidResolver/src/GradleResolver.cs:1093)
Google.RunOnMainThread:ExecutePollingJobs () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:409)
Google.RunOnMainThread:<ExecuteAllUnnested>m__12 () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:541)
Google.RunOnMainThread:RunAction (System.Action) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
Google.RunOnMainThread:ExecuteAllUnnested (bool) (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
Google.RunOnMainThread:ExecuteAll () (at /Users/drsanta/dev/tmp/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:512)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
`
What should I do ? I impoted only the firebase database
Yeah, I have caught this problem too, and need to manually add Firebase App (Core) package, which should be dependency but seem like its not.
This could happen if you mix different versions of the libraries. Can you verify that all the Firebase libraries you're using are the same version?
The issue is that there is no way to specify exact dependency version for Unity Package Manager unfortunately. The version number used in package manifest is more like the min version unless the major version is changed.
That is why we documented this at the bottom of this section
There might be something we can do in the EDM4U side to fill this void. It will take some time to develop since it changes not only EDM4U, but also the metadata from registry server and the release process.
Until then, please make sure not only Firebase packages are in the same version, but also Firebase App (Core), which installed as a dependency, is in the same version as well.

Unity async task can't be called outside of main thread?

I need to convert a .txt file called TheFile to a dictionary called theFileDictionary and then save it to a binary file.
I am doing this with the following class FileHandler:
public class FileHandler : MonoBehaviour
{
[SerializeField] TextAsset theFile;
FileStream file;
public async Task LoadTheFileIntoBinaryFile()
{
BinaryFormatter formatter = new();
file = File.Create(Application.persistentDataPath + "/foods.txt");
/*line 33, error gets called*/ await Task.Run(() => { formatter.Serialize(file, LoadTheFileIntoDictionary()); } );
file.Close();
}
Dictionary<string, string[]> LoadTheFileIntoDictionary()
{
/*line 39, error occurs*/Dictionary<string, string[]> theFileDictionary =
theFile
.text
.Split('\n')
.Select(x => x.Split('\t'))
.ToDictionary(x => x[ApplicationInfo.GetLanguageIndex()].Replace("-", " "));
return blsDictionary;
}
}
When starting LoadTheFileIntoBinaryFile() I get this error:
UnityException: get_bytes can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.TextAsset.get_text () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/TextAsset.cs:23)
FileHandler.LoadTheFileIntoDictionary () (at Assets/Scripts/Daten/FileHandler.cs:39)
FileHandler+<>c__DisplayClass3_0.b__0 () (at Assets/Scripts/Daten/FileHandler.cs:33)
System.Threading.Tasks.Task.InnerInvoke () (at :0)
System.Threading.Tasks.Task.Execute () (at :0)
--- End of stack trace from previous location where exception was thrown ---
From what the error says it seems to be that the Dictionary has to be initialised in Awake() or Start(). When I do that it kinda works but I don't need the method in Start(), I need it sometimes later (and I still need it to load asynchronously)...
I tried declaring and implementing the Dictionary<string, string[]> in Start() but with no change in result.
What am I doing wrong?

Catel with Xamarin.Forms

I can't get Xamarin.Forms and Catel work together.
I saw this sample but it seems it's out of date.
When I download Catel via NuGet, i get different issues for different versions:
v5.1:
Compile-time exception:
Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Obsolete, Version=4.2.4.0, Culture=neutral, PublicKeyToken=1ca091877d12ca03'. Perhaps it doesn't exist in the Mono for Android profile?
v5.0:
Runtime exception (when creating new App();):
Could not load signature of Catel.MVVM.IViewModelFactory:CreateViewModel due to: Could not resolve type with token 01000061 (from typeref, class/assembly System.ComponentModel.IDataErrorInfo, Catel.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null) assembly:Catel.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null type:System.ComponentModel.IDataErrorInfo member:<none>
v4.5.*
Using ViewModelBase:
Runtime exception when creating Application object:
System.TypeLoadException: Could not resolve type with token 01000097 (from typeref, class/assembly System.Reflection.BindingFlags, Catel.Core, Version=4.5.4.0, Culture=neutral, PublicKeyToken=null)
My implementation of IViewModel:
Ok, MainPage loading, binding works, Constructor gets right services via parameters, but, for example, when I call '_uiVisualizerService.Show( subPageViewModel );' from command, it throws 'InvalidCastException'. Last line in Catel log before exception: Injecting properties into type 'SubPage' after construction. But SubPage and SubPageViewModel are absolutely empty.
Details:
---> System.InvalidCastException: Specified cast is not valid.
at Catel.Services.UIVisualizerService+<ShowAsync>d__9.MoveNext () [0x00096]
in C:\CI_WS\Ws\97969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:151
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011]
in <183b200ee49746d48fc781625979428e>:0
at System.Threading.Tasks.Task'1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b]
in <183b200ee49746d48fc781625979428e>:0
at System.Threading.Tasks.Task'1[TResult].get_Result () [0x0000f]
in <183b200ee49746d48fc781625979428e>:0
at Catel.Services.UIVisualizerService.Show (Catel.MVVM.IViewModel viewModel, System.EventHandler``1[TEventArgs] completedProc) [0x00000]
in C:\CI_WS\Ws\97969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:125
at XamarinFormsCatel.ViewModels.MainPageViewModel.OnGo () [0x00015]
in C:\!Work\Test\XamarinFormsCatel\XamarinFormsCatel\XamarinFormsCatel\XamarinFormsCatel\ViewModels\MainPageViewModel.cs:34
at Xamarin.Forms.Command+<>c__DisplayClass3_0.<.ctor>b__0 (System.Object o) [0x00000]
in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:73
at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000]
in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:107
at Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked () [0x0000a]
in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Button.cs:121
at Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer+ButtonClickListener.OnClick (Android.Views.View v) [0x0000b]
in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:298
at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x0000f]
in <71828dd8fb5f4508815e23d6996c45c2>:0
at (wrapper dynamic-method) System.Object:4c9f6786-8ab0-4bd8-bdb1-4cc7a3d7ddc7 (intptr,intptr,intptr)
-> (Inner Exception #0) System.InvalidCastException: Specified cast is not valid.
at Catel.Services.UIVisualizerService+<ShowAsync>d__9.MoveNext () [0x00096]
in C:\CI_WS\Ws\97969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:151 <---
What i do:
Change defalt Catel.MVVM.dll reference in android project from MonoAndroid to portable-net45+wp8+win8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10. if this is not done, compilation will fail.
MainPage.xaml
<catel:ContentPage ...
xmlns:catel="clr-namespace:Catel.Windows.Controls;assembly=Catel.MVVM">
MainPageViewModel.cs
public class MainPageViewModel : ViewModelBase { }
App.cs
public class App : Catel.Xamarin.Forms.Application<Views.MainPage> { }
MainActivity.cs (Android)
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate( Bundle bundle )
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate( bundle );
Xamarin.Forms.Forms.Init( this, bundle );
var app = new App();
LoadApplication( app );
}
}
Windows 7, 64x.
Xamarin.Forms: 2.3.4.267
Any help very appreciated.
The team is working on improved support for Xamarin.Forms. At the moment there are no examples. The expectation is to finalize v5 support for Xamarin.Forms on this over the next few months.

System.InvalidProgramException Invalid IL code in System.Data.Objects.ObjectContext:.ctor (string,string): method body is empty

Im using mono(3.0.3) on a raspberry pi. Everything is working properly except entity framework. I can login with no problem into my site but the second I enter an area where there is entity framework i get the following error with XSP:
Application Exception
System.InvalidProgramException
Invalid IL code in System.Data.Objects.ObjectContext:.ctor (string,string): method body is empty.
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): AdwenModel.
Exception stack trace:
at AdwenModel.AdwenEntities1..ctor (System.String connectionString) [0x00000] in <filename unknown>:0
at AdwenWeb.App_Code.AdwenConnection.getDataContextAdwen () [0x00000] in <filename unknown>:0
at AdwenWeb.Management.overview.createObjectTable () [0x00000] in <filename unknown>:0
at AdwenWeb.Management.overview.Page_Load (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0
at System.Web.UI.Control.OnLoad (System.EventArgs e) [0x00029] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web.UI/Control.cs:1211
at System.Web.UI.Control.LoadRecursive () [0x00031] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web.UI/Control.cs:1641
at System.Web.UI.Page.ProcessLoad () [0x0004a] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web.UI/Page.cs:1490
at System.Web.UI.Page.ProcessPostData () [0x0004d] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web.UI/Page.cs:1475
at System.Web.UI.Page.InternalProcessRequest () [0x001bf] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web.UI/Page.cs:1442
at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x00062] in /opt/mono-3.0/mono/mcs/class/System.Web/System.Web.UI/Page.cs:1269
Version Information: 3.0.3 (master/c1b505c Thu Dec 6 09:17:47 UTC 2012); ASP.NET Version: 4.0.30319.17020
Don't really know what else could be wrong.
I don't know much about the Entity Framework support in Mono but what I do know is that they have included EF6 in Mono, and System.Data.Objects is no longer the namespace for ObjectContext in EF6. Whatever is causing the failure should be looking for System.Data.Entity.Core.Objects.ObjectContext instead.
Hope this helps.

MonoTouch: using embedded resx files on iPhone build

I'm able to load and access resx files in Simulator builds of my iPhone app built using MonoTouch. The resx file entry in the csproj file looks like:
<ItemGroup>
<EmbeddedResource Include="MapMenu\Resources\MapMenu.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>MapMenu.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
The .resx file itself has an entry like this:
<data name="Main_Menu" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Main Menu.mm;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
and the generated MapMenu.Designer.cs file has this:
internal static string Main_Menu {
get {
return ResourceManager.GetString("Main_Menu", resourceCulture);
}
}
As mentioned above, calling the Main_Menu accessor works fine on the simulator. On the device, however, it produces:
<Notice>: Unhandled Exception: System.MissingMethodException: No constructor found for System.Resources.RuntimeResourceSet::.ctor(System.IO.UnmanagedMemoryStream)
<Notice>: at System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0
<Notice>: at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0
<Notice>: at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in <filename unknown>:0
<Notice>: at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0
<Notice>: at System.Resources.ResourceManager.GetString (System.String name, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
<Notice>: at MapMenu.Resources.MapMenu.get_Main_Menu () [0x00000] in <filename unknown>:0
Did a few sanity checks, and am wondering at this point if this really is missing functionality in Monotouch.
Thanks,
It looks like a bug in the linker that removes a constructor that is only called through reflection by the resource loader code. As a workaround, you can disable the linker (either using -nolink if you use mtouch directly, or by specifying the linker options in MonoDevelop.
Please file a bug.