System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:<ToLookup`2> - xamarin.ios

here is my Code
public int GetUsersSqlCount()
{
// Here i get the Error
return this.GetUsersSql().Count();
}
public IEnumerable<CsUser> GetUsersSql()
{
return (from x in this._storage.CsUsers
join y in this._storage.CeMitarbs on x.MitNr equals y.MitNr
select x).OrderBy(x => x.KurzZch);
}
I get the following Error:
Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:<ToLookup`2>m__5A<Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb, System.Nullable`1<int>> (Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb)' while running with --aot-only.
at System.Linq.Enumerable.ToLookup[CeMitarb,Nullable`1,CeMitarb] (IEnumerable`1 source, System.Func`2 keySelector, System.Func`2 elementSelector, IEqualityComparer`1 comparer) [0x00079] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2966
at System.Linq.Enumerable.ToLookup[CeMitarb,Nullable`1] (IEnumerable`1 source, System.Func`2 keySelector, IEqualityComparer`1 comparer) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2934
at System.Linq.Enumerable+<CreateJoinIterator>c__Iterator18`4[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser,Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb,System.Nullable`1[System.Int32],Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser].MoveNext () [0x00023] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:1157
at System.Collections.Generic.List`1[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.ToArray[CsUser] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
at System.Linq.QuickSort`1[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser]..ctor (IEnumerable`1 source, System.Linq.SortContext`1 context) [0x00000] in <filename unknown>:0
at System.Linq.QuickSort`1+<Sort>c__Iterator2F[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser].MoveNext () [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Count[CsUser] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
at CSMobile.Logic.Forms.Login_Dal.GetUsersSqlCount () [0x00000] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Dal.cs:38
at CSMobile.Logic.Forms.Login_Logic.GetUsers () [0x0001f] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Logic.cs:198
at CSMobile.Logic.Forms.Login_Logic.Anmelden2 (Int32 selectedProduct) [0x00050] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Logic.cs:416
at CSMobile.UI.Login.Logic_LoginStepCompleted (Login_StepResult result) [0x0003e] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Forms/Login.cs:325
at CSMobile.Logic.Forms.Login_Logic.Anmelden1 () [0x00084] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Logic.cs:364
at CSMobile.UI.Login.StartLogin () [0x00000] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Forms/Login.cs:75
at CSMobile.UI.Login.Pad_Start_TouchUpInside (MonoTouch.Foundation.NSObject sender) [0x00000] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Forms/Login.cs:235
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:34
at CSMobile.UI.Application.Main (System.String[] args) [0x0000a] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Main.cs:18
[ERROR] FATAL UNHANDLED EXCEPTION: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:<ToLookup`2>m__5A<Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb, System.Nullable`1<int>> (Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb)' while running with --aot-only.

I think this limitation here is actually due to Generic Virtual Methods - http://docs.xamarin.com/ios/about/limitations#Generic_Virtual_Methods
There's a discussion of a very similar problem on the mailing list:
http://monotouch.2284126.n4.nabble.com/LINQ-JIT-error-again-td3800970.html;cid=1338984263803-35#a3800169
It didn't sound like that thread found a solution
It might be worth contacting Xamarin support directly on this one. http://bugzilla.xamarin.com/

Generics are a bit weird on MonoTouch due to AOT compilation. A true runtime / JIT is disallowed in iOS, so it must compile everything ahead-of-time.
In this particular case, your method which returns IEnumerable<CsUser> is most likely the culprit. Generic interfaces cause problems. Try changing your return type to a List<CsUser> or any other concrete class that implements IEnumerable<CsUser>.

OrderBy is known to fail in this scenario. This appears to be fixed in MonoTouch version 2.10 but unfortunately if you're using an engine like Unity, that only ships with 2.6 currently (as of 4.3.x).
https://bugzilla.xamarin.com/show_bug.cgi?id=2155#c11

I don't know a convenient solution for Xamarin at the moment.
However there is such a solution for Unity 3D.
You can try LINQ to iOS. It's a custom implementation of LINQ to Objects extension methods that works on iOS without JIT-compile errors. If you're using Xamarin you may try to take .dll from LINQ to iOS and use it in your project. After all, Xamarin and Unity both use Mono compiler.

Related

ServiceStack.LicenseException with a valid License Key

I am trying to register the license key by the Application_Start method. When I execute Licensing.RegisterLicense("{LicenseKey}"), the method LicenseUtils.ActivatedLicenseFeatures() returns the value "Text". But when I execute new AppHost().Init(), it gives me the following error:
Application Exception
ServiceStack.LicenseException
The free-quota limit on '10 ServiceStack Operations' has been reached. Please see https://servicestack.net to upgrade to a commercial license or visit https://github.com/ServiceStackV3/ServiceStackV3 to revert back to the free ServiceStack v3.
Description: HTTP 500. Error processing request.
Details: Non-web exception. Exception origin (name of application or object): ServiceStack.Text.
Exception stack trace:
at ServiceStack.LicenseUtils.ApprovedUsage (LicenseFeature licenseFeature, LicenseFeature requestedFeature, Int32 allowedUsage, Int32 actualUsage, System.String message) [0x00026] in <filename unknown>:0
at ServiceStack.LicenseUtils.AssertValidUsage (LicenseFeature feature, QuotaType quotaType, Int32 count) [0x00118] in <filename unknown>:0
at ServiceStack.Host.ServiceMetadata.Add (System.Type serviceType, System.Type requestType, System.Type responseType) [0x002c9] in <filename unknown>:0
at ServiceStack.Host.ServiceController.RegisterService (ITypeFactory serviceFactoryFn, System.Type serviceType) [0x00137] in <filename unknown>:0
at ServiceStack.Host.ServiceController.Register (ITypeFactory serviceFactoryFn) [0x0001a] in <filename unknown>:0
at ServiceStack.Host.ServiceController.Init () [0x00016] in <filename unknown>:0
at ServiceStack.ServiceStackHost.Init () [0x00073] in <filename unknown>:0
at API.Global.Application_Start (System.Object sender, System.EventArgs e) [0x00016] in API/Global.asax.cs:163
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /private/tmp/source-mono-mac-4.2.0-branch-c6sr1/bockbuild-mono-4.2.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:295
Version Information: 4.2.2 (explicit/996df3c Wed Jan 20 00:19:48 EST 2016); ASP.NET Version: 4.0.30319.17020
Powered by Mono
I already tried to update the ServiceStack package, with no success.
This is because you're using a ServiceStack.Text License which only covers usage for the ServiceStack.Text NuGet Package with packages from the full ServiceStack framework.

PlatformNotSupportedException for HttpClient and Await/Async operation at PCL and Xamarin.iOS app

I'm trying to add await/async support to my Portable Class Library.
In my Xamarin.iOS project I created a reference to PCL (profile 78).
Every time I'm trying to call PCL async method:
var result = await new Class1().Do();
I'm getting the following error (stacktrace):
System.PlatformNotSupportedException: This platform is not supported.
2014-03-29 17:48:06.634 HelloWorld5[2014:60b] Unhandled managed exception: This platform is not supported. (System.PlatformNotSupportedException)
at System.ExecutionContextLightup.Run (System.ExecutionContextLightup executionContext, System.Action`1 callback, System.Object state) [0x00000] in <filename unknown>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <filename unknown>:0
at Microsoft.Runtime.CompilerServices.TaskAwaiter+<>c__DisplayClassa.<OnCompletedInternal>b__1 (System.Object state) [0x00000] in <filename unknown>:0
at MonoTouch.UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey89.<>m__A9 () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pmcs-compat.UIKitSynchronizationContext.cs:24
at MonoTouch.Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/.pmcs-compat.NSAction.cs:87
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string
[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pmcs-compat.UIApplication.cs:38
at HelloWorld5.Application.Main (System.String[] args) [0x00001] in c:\Downloads\HelloWorld5.BackgroundTest\HelloWorld5\HelloWorld5\Main.cs:17
The program 'Mono' has exited with code 0 (0x0).
Debugging session ended.
The program '[5932] HelloWorld5.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[5932] HelloWorld5.vshost.exe' has exited with code 0 (0x0).
I'm using STABLE version of Xamarin software.
Please find the sample project here:
https://dl.dropboxusercontent.com/u/19503836/PCLAndAsyncWithXamariniOS.zip

Teechart application crashing in iphone

when using steema Teechart, its working fine in simulator, but application crashing when using in iphone,
its shows following error
System.NullReferenceException: Object reference not set to an instance of an object
at Steema.TeeChart.TChart.ApplyScroll () [0x00000] in :0
at Steema.TeeChart.TChart.m__0 (System.Object sender, System.EventArgs e) [0x00000] in :0
at MonoTouch.UIKit.UIScrollView+_UIScrollViewDelegate.Scrolled (MonoTouch.UIKit.UIScrollView scrollView) [0x0000d] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIScrollView.g.cs:991
at MonoTouch.UIKit.UIScrollView.SetContentOffset (PointF contentOffset, Boolean animated) [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIScrollView.g.cs:208
at Steema.TeeChart.TChart.Draw (RectangleF rect) [0x00000] in :0
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at CropManageriPhone.Application.Main (System.String[] args) [0x00000] in /Users/vss1/VSS Projects/CP Live/CropManageriPhone04022013/CropManageriPhone/Main.cs:17
and We are using monotouch version 6.0.4
i found solution for this,
i set ZoomScrollStyle for the chart control,
_controller.chart.Aspect.ZoomScrollStyle=Steema.TeeChart.Drawing.Aspect.ZoomScrollStyles.Manual;

How to add CoreData Model File .momd into MonoTouch project

The MonoTouch solution includes two projects.
MonoTouch Binding Project: API Contract interfaces for linked native
ObjC library
Test Client Application
The native ObjC library requires to include Core Data Model file (.momd). I have added it to the project of Test App.
But app crashes with the following error:
Unhandled Exception: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Cannot create an NSPersistentStoreCoordinator with a nil model
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr_bool (intptr,intptr,intptr,bool)
at MonoTouch.UIKit.UIViewController.PresentModalViewController (MonoTouch.UIKit.UIViewController modalViewController, Boolean animated) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIViewController.g.cs:261
at CombinedControllerApp.MainController.<ViewDidLoad>m__2 (System.Object , System.EventArgs ) [0x0003d] in /Users/mahmood1/Documents/Projects/TouchNote-Prototype/CombinedControllerApp/MainController.cs:96
at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIControl.cs:30
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at CombinedControllerApp.Application.Main (System.String[] args) [0x00000] in /Users/mahmood1/Documents/Projects/TouchNote-Prototype/CombinedControllerApp/Main.cs:17
[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Cannot create an NSPersistentStoreCoordinator with a nil model
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr_bool (intptr,intptr,intptr,bool)
at MonoTouch.UIKit.UIViewController.PresentModalViewController (MonoTouch.UIKit.UIViewController modalViewController, Boolean animated) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIViewController.g.cs:261
at CombinedControllerApp.MainController.<ViewDidLoad>m__2 (System.Object , System.EventArgs ) [0x0003d] in /Users/mahmood1/Documents/Projects/TouchNote-Prototype/CombinedControllerApp/MainController.cs:96
at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIControl.cs:30
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at CombinedControllerApp.Application.Main (System.String[] args) [0x00000] in /Users/mahmood1/Documents/Projects/TouchNote-Prototype/CombinedControllerApp/Main.cs:17
How to add this needed CoreData Model File into Test Application that it will be visible for the native library?
Thanks!
(Sources are here : http://www.axifile.com/en/71EC96914A)
Per my comment:
Adding most files like this to your project with Build Action of Content will solve the issue.

EMGU library OPENCV problem with native memroy management - does really work with mono?

we are working in a project involving the use of EMGU and in particoular the SVM functions of OpenCV and we have a problem using Mono on a Ubuntu platform and we don't have this problem on windows. The problem appears when we call the Emgu.CV.ML.SVM.Train method. All the parameters are correct and we canno't debug the wrapped code...
We have tried to increase the Shared Memory and other tricks but it doesn't work.
Do you have any idea?
Thank you
Angelo
Unhandled Exception: Emgu.CV.CvException: OpenCV: requested size is negative or too big
at Emgu.CV.CvInvoke.CvErrorHandler (Int32 status, System.String funcName, System.String errMsg, System.String fileName, Int32 line, IntPtr userData) [0x00000]
at (wrapper native-to-managed) Emgu.CV.CvInvoke:CvErrorHandler (int,intptr,intptr,intptr,int,intptr)
at (wrapper managed-to-native) Emgu.CV.ML.MlInvoke:CvSVMTrain (intptr,intptr,intptr,intptr,intptr,Emgu.CV.ML.Structure.MCvSVMParams)
at Emgu.CV.ML.SVM.Train (Emgu.CV.Matrix`1 trainData, Emgu.CV.Matrix`1 responses, Emgu.CV.Matrix`1 varIdx, Emgu.CV.Matrix`1 sampleIdx, Emgu.CV.ML.SVMParams parameters) [0x00000]
at Segmentation.ImageFeatures.LeafHog.TrainModel (IDictionary`2 dicInOutImage) [0x00000]
at Segmentation.ImageSegmentators.Composite.TrainModel (IDictionary`2 dicInOutImage) [0x00000]
at Segmentation.ImageSegmentators.CompositionMlpRprop.TrainModel (IDictionary`2 dicInOutImage) [0x00000]
at Segmentation.GeneticConfig.ChromoCreator.GetASegmentation (IConfigChromosome configChromosome, IDictionary`2 dicInOutImageTrain) [0x00000]
at Segmentation.GeneticConfig.ConfigChromoProvider.AddChromosomeIfNew (IConfigChromosome chromo) [0x00000]
at Segmentation.GeneticConfig.ConfigChromosome.Generate () [0x00000]
at Segmentation.GeneticConfig.ConfigChromosome..ctor (Int32 chromoLength, IConfigChromoProvider cProvider) [0x00000]
at Segmentation.GeneticConfig.ConfigChromosome.CreateNew () [0x00000]
at AForge.Genetic.Population..ctor (Int32 size, IChromosome ancestor, IFitnessFunction fitnessFunction, ISelectionMethod selectionMethod) [0x00000]
at SegmentationCLI.Program.Main (System.String[] args) [0x00000]

Resources