I have a native Xamarin.Android app I've built a few years back and I've been maintaining it since then. Lately, I tried to build a new release but the app keeps crashing. I did tens of releases in the past using the same project and compilation settings. Here's an exemple of a stack trace I get in release:
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies.
[mono-rt] at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction10-21 13:24:49.970 F/mono-rt (15785): File name: 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
[mono-rt] at Java.Interop.JniEnvironmentInfo..ctor () [0x00006] in :0
[mono-rt] at Java.Interop.JniEnvironment+c.b__35_0 () [0x00000] in :0
[mono-rt] at System.Threading.ThreadLocal`1[T].GetValueSlow () [0x00031] in :0
[mono-rt] at System.Threading.ThreadLocal`1[T].get_Value () [0x0003e] in :0
[mono-rt] at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in :0ds.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0002d] in :0
[mono-rt] at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeObjectMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00018] in :0
[mono-rt] at Java.Interop.JniEnvironment+StaticMet10-21 13:24:49.970 F/mono-rt (15785): at Android.OS.Looper.get_MainLooper () [0x0000a] in :0
[mono-rt] at Android.Runtime.AndroidEnvironment.GetDefaultSyncContext () [0x00000] in :0
[mono-rt] at System.AndroidPlatform.GetDefaultSyncContext () [0x00000] in :0
[mono-rt] at System.Threading.SynchronizationContext.GetThreadLocalContext () [0x00005] in :0
[mono-rt] at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task ignored, System.Boolean canInlineContinuationTask) [0x00003] in :0
[mono-rt] at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
[mono-rt] at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x0004f] in :0
[mono-rt] at System.Threading.Tasks.TaskFactory`1+c__DisplayClass38_0`1[TResult,TArg1].b__0 (System.IAsyncResult iar) [0x00008] in :0
[mono-rt] at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in 10-21 13:24:49.970 F/mono-rt (15785): at (wrapper managed-to-native) System.Runtime.Remoting.Messaging.AsyncResult.Invoke(System.Runtime.Remoting.Messaging.AsyncResult)
[mono-rt] at System.Runtime.Remoting.Messaging.AsyncResult.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in :0
[mono-rt] at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in :0
From the stack trace, I have a feeling it might be a problem with the linker, but I have tried all 3 settings (Don't link, link SDK assemblies only, link all). When changing some code here and there, I have sometimes slightly different stack traces, but nothing really helpful. Here's the compilation settings I'm using:
From time to time, the app will launch successfully without changing anytime special. It will only work once.
What I'm I missing?
I am pretty sure that you have some weird behavior in release. Since you use mono on android you may call an await function somewhere that return a Task<T> you must not use the await but .GetAwaiter().Result.
https://github.com/xamarin/xamarin-android/issues/6409
Make sure your .NET framework is patched. Microsoft released patches to .NET to allow Portable Class Libraries to properly find the appropriate runtime (KB2468871). If you are seeing the above exception (or something like it), it means you’re missing the latest .NET framework patches.
You can read more about Portable Class Libraries on MSDN.
Related
I'm creating an app using xamarin Cross Platform. Everything is working in debug, but when i bulid app in release version, app crashes. Application output:
ERROR:
[mono] Unhandled Exception: [mono] System.MissingMethodException:
Method not found: 'System.Net.Http.HttpClient.GetAsync'.
[mono] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[<LoadData>d__0] (POSSector.Mobile.<LoadData>d__0& stateMachine)
[0x00000] in <filename unknown>:0
[mono] at POSSector.Mobile.LoginViewModel.LoadData ()
[0x00000] in <filename unknown>:0
[mono] at POSSector.Mobile.LoginCommand+<Bind>d__3.MoveNext () [0x00000] in <filename unknown>:0
[mono] --- End of stack trace from previous location where exception was thrown --- [mono] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
[0x00000] in <filename unknown>:0 [mono] at System.Runtime.CompilerServices.TaskAwaiter.GetResult ()
[0x00000] in <filename unknown>:0 [mono] at POSSector.Mobile.LoginCommand+<Execute>d__0.MoveNext ()
[0x00000] in <filename unknown>:0
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Method not found: 'System.Net.Http.HttpClient.GetAsync'.
In Options - Android Build- Linker / I set Don link and my App work !
Info for problem
I have an application which utilizes GeckoFX/xulrunner 22.
This program works great in Windows but no matter what I do I cannot get it to run in Linux nor Mac.
The primary focus is Mac though.
I've tried swapping out different versions of Windows, Linux & Mac xulrunner run-times as well as different initialization strings to try including both the Windows, Linux and Mac versions (of course only one at a time) like:
Gecko.Xpcom.Initialize("lib/xulrunner");
Gecko.Xpcom.Initialize("lib/XUL.framework/Versions/Current");
I have also tried prefixing with "./" as well as using code to obtain the current working directory to prepend to the path.
I've also tried copying over a dozen different versions of xul.dll into the executable folder and subdirectories within it.
No matter what I think to try, or search this site/google to try nothing has worked.
This is failing on the Initialize() call.
The program/class names are only starred out so this is not the first thing popping up in google when people search for the program.
Although my biggest concern is getting this running on Mac, I will also mention due to other posts on Stack Overflow and alike that on my Linux system, I have tried having various versions of Firefox installed and the path pointed to as per other peoples' instructions. It always shows the same error as on Mac.
Error follows: Unhandled Exception:
System.DllNotFoundException: xul
at (wrapper managed-to-native) Gecko.Xpcom:Alloc (intptr)
at Gecko.nsAString..ctor () [0x00000] in :0
at Gecko.nsAString..ctor (System.String value) [0x00000] in :0
at Gecko.Xpcom.Initialize (System.String binDirectory) [0x00000] in :0
at **********.**********.CreateBrowsers () [0x00000] in :0
at **********.**********.**********_Shown (System.Object sender, System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.OnShown (System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in :0
at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm) [0x00000] in :0
at **********.Program.Main () [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: xul
at (wrapper managed-to-native) Gecko.Xpcom:Alloc (intptr)
at Gecko.nsAString..ctor () [0x00000] in :0
at Gecko.nsAString..ctor (System.String value) [0x00000] in :0
at Gecko.Xpcom.Initialize (System.String binDirectory) [0x00000] in :0
at **********.**********.CreateBrowsers () [0x00000] in :0
at **********.**********.**********_Shown (System.Object sender, System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.OnShown (System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in :0
at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm) [0x00000] in :0
at **********.Program.Main () [0x00000] in :0
Firstly, to my knowledge no one has ever run geckofx on OSX.
The problem you are seeing is probably easy fixable but before getting geckofx to work on mac you will likely hit more problems.
Geckofx's architecture on Windows is simple. The GeckoWebBrowser control is a winforms based control, which underneath are win32 controls and gecko/firefox on windows also uses win32 controls.
However on Linux things are a little more complicated as gecko/firefox uses GTK while the mono winform implementation is based upon X11. Hence geckofx has some fairly complex code to make that all work. (Which is why one needs to use a different build of geckofx on Linux (one with the GTK flag defined).
So firstly on OSX you have to determine what UI toolkit does mono uses for winforms, is it X11, carbon or something else? Then you have to determine which toolkit Firefox uses on OSX, carbon, cocoa or something else? If they happen to match then its probably worth proceeding with the windows build of geckofx. If they are different then you will probably have to modify geckofx itself to deal with this issue.
Now on to the DllNotFoundException.
The PInvoke/DllImport calls are probably looking for "xul.dll". This file could be named something different in OSX's firefox (eg. libxul.so) so a dllmap config file is needed to map xul.dll to the correct file.
Also setting these two environment variables, MONO_LOG_LEVEL="debug" and MONO_LOG_MASK="dll" should provide you with useful debug information.
Additionally one can use an absolute path for Gecko.Xpcom.Initialize to avoid any confusion about finding the path.
I am having problems with MVC4 on Mono 3. I am using the latest version in Xamarin Studio with the latest updates but when trying a HTTP POST to the web server it is returning the following error. I am using the DLL's for MVC4 from windows as the guides suggest and the Mono version of System.Web 4.0.0.0.
Any ideas how to resolve this issue or am I just better reverting to MVC3?
System.TypeLoadException
Could not load type 'System.Web.UnvalidatedRequestValuesBase' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Web.Mvc.
Exception stack trace:
at System.Web.Mvc.UnvalidatedRequestValuesWrapper.get_Form () [0x00000] in <filename unknown>:0 at System.Web.Mvc.FormValueProvider..ctor (System.Web.Mvc.ControllerContext controllerContext, IUnvalidatedRequestValues unvalidatedValues) [0x00000] in <filename unknown>:0 at System.Web.Mvc.FormValueProviderFactory.GetValueProvider (System.Web.Mvc.ControllerContext controllerContext) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ValueProviderFactoryCollection+<>c__DisplayClassc.<GetValueProvider>b__7 (System.Web.Mvc.ValueProviderFactory factory) [0x00000] in <filename unknown>:0 at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator25`2[System.Web.Mvc.ValueProviderFactory,<>f__AnonymousType2`2[System.Web.Mvc.ValueProviderFactory,System.Web.Mvc.IValueProvider]].MoveNext () [0x00059] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.Core/System.Linq/Enumerable.cs:2269 at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator33`1[<>f__AnonymousType2`2[System.Web.Mvc.ValueProviderFactory,System.Web.Mvc.IValueProvider]].MoveNext () [0x0006f] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.Core/System.Linq/Enumerable.cs:3120 at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator25`2[<>f__AnonymousType2`2[System.Web.Mvc.ValueProviderFactory,System.Web.Mvc.IValueProvider],System.Web.Mvc.IValueProvider].MoveNext () [0x00059] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.Core/System.Linq/Enumerable.cs:2269 at System.Collections.Generic.List`1[System.Web.Mvc.IValueProvider].AddEnumerable (IEnumerable`1 enumerable) [0x00013] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/corlib/System.Collections.Generic/List.cs:134 at System.Collections.Generic.List`1[System.Web.Mvc.IValueProvider]..ctor (IEnumerable`1 collection) [0x0002f] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/corlib/System.Collections.Generic/List.cs:69 at System.Linq.Enumerable.ToList[IValueProvider] (IEnumerable`1 source) [0x00006] in /private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.3/mcs/class/System.Core/System.Linq/Enumerable.cs:2951 at System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider (System.Web.Mvc.ControllerContext controllerContext) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerBase.get_ValueProvider () [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerActionInvoker.GetParameterValue (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ParameterDescriptor parameterDescriptor) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerActionInvoker.GetParameterValues (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionDescriptor actionDescriptor) [0x00000] in <filename unknown>:0 at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass25.<BeginInvokeAction>b__1e (System.AsyncCallback asyncCallback, System.Object asyncState) [0x00000] in <filename unknown>:0
Version Information: 3.2.3 ((no/8d3b4b7 Mon Sep 16 23:46:28 EDT 2013); ASP.NET Version: 4.0.30319.17020
Since I had the same error with MVC 3 Razor like you I solved my problem by
copying following DLL's from a MVC 3 Razor Visual Studio project to my mono project.
System.Web.Helpers.dll
System.Web.Mvc.dll
System.Web.Razor.dll
System.Web.WebPages.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.Razor.dll
This might help as well:
http://blog.yojimbocorp.com/2012/08/27/asp-net-mvc3-with-razor-view-engine-using-monodevelop-and-ubuntu-12-04/
Is there any way to use Excel / Office libraries in Ubuntu?
I've developed a C# program that glues together an Excel spreadsheet and some VB macros. It uses the following.
Excel and Office libraries: Microsoft.Vbe.Interop.dll
Microsoft.Office.Interop.Excel.dll and Office.dll. It works perfectly fine in Windows but I can't manage to get it running on Ubuntu using Mono 3.2.
When I try to execute it (after adding the libraries that I explicitly imported using gacutil -l XXXX.dll)
the output is the following:
[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: ole32.dll
at (wrapper managed-to-native) System.__ComObject:CoCreateInstance (System.Guid,intptr,uint,System.Guid,intptr&)
at System.__ComObject.Initialize (System.Type t) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.__ComObject:Initialize (System.Type)
at Mono.Interop.ComInteropProxy.CreateProxy (System.Type t) [0x00000] in <filename unknown>:0
at System.Runtime.Remoting.RemotingServices.CreateClientProxyForComInterop (System.Type type) [0x00000] in <filename unknown>:0
at System.Runtime.Remoting.Activation.ActivationServices.CreateProxyForType (System.Type type) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at MyProgram.Program.joinMacroAndExcel () [0x00000] in <filename unknown>:0
at MyProgram.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
Any help or direction would be highly appreciated. Thanks in advance.
Josh
The Excel / Office integration libraries require Office to already be installed to run - just copying the PIAs (e.g. Microsoft.Office.Interop.Excel.dll) is insufficient, as they are to act as the bridge to the COM layer exposed by Excel et al. Without the COM layer, there's nothign to perform the work you're asking of it.
I've recently came across the blog article Monovation: Assembly Injection into Live Processes of Miguel de Icaza.
I've tried to reproduce it with no luck. My command line was
'csharp --attach 5612'
where 5612 was the pid of a simple running mono 'Hello World' console application.
I've got an exception (see the stack trace above).
What I've tried so far:
using Mono 2.10.8 (csharp and csharp2 commands for .NET 4 and 2 )
using Mono 3.2.3 (only csharp command exists)
Q1: Missed I something?
Q2: Is it possible that this virtual machine attach facility (see Monovation: Assembly Injection into Live Processes) is available only in Linux installations? (I am using Windows 7) It sounds an easy answer, but Miguel does not mention platform restriction in his article, and the whole point of mono is the multiplatform, is not it? So I can not believe it so easy.
Q3: What about Mac? Is there any chance it will work in a Mac, or we must look elsewhere?
Thx in advance
Stack trace:
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd ()
at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Unix.UnixUserInfo.GetRealUserId () [0x00000] in <filename unknown>:0
at Mono.Unix.UnixUserInfo.GetRealUser () [0x00000] in <filename unknown>:0
at Mono.Attach.VirtualMachine.Attach (System.String agent, System.String args) [0x00000] in <filename unknown>:0
at Mono.ClientCSharpShell..ctor (Mono.CSharp.Evaluator evaluator, Int32 pid) [0x00000] in <filename unknown>:0
at Mono.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.EntryPointNotFoundException: Mono_Posix_Syscall_get_at_fdcwd
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:get_at_fdcwd ()
at Mono.Unix.Native.Syscall..cctor () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Unix.UnixUserInfo.GetRealUserId () [0x00000] in <filename unknown>:0
at Mono.Unix.UnixUserInfo.GetRealUser () [0x00000] in <filename unknown>:0
at Mono.Attach.VirtualMachine.Attach (System.String agent, System.String args) [0x00000] in <filename unknown>:0
at Mono.ClientCSharpShell..ctor (Mono.CSharp.Evaluator evaluator, Int32 pid) [0x00000] in <filename unknown>:0
at Mono.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0