I retrieve this crash log about my app.
System.NullReferenceExceptionObject reference not set to an instance of an object
Raw TouristApp.PuntiEventiView.c__AnonStorey1.<>m__0()
Foundation.NSActionDispatcher.Apply()
UIKit.UIApplication.UIApplicationMain(int, string[], intptr, intptr)(wrapper managed-to-native)
UIKit.UIApplication.Main(string[] args, IntPtr principal, IntPtr delegate)
UIKit.UIApplication.Main(string[] args, string principalClassName, string delegateClassName)
TouristApp.Application.Main(string[] args)
I have no clue about the error, in my class (PuntiEventiView) there is no call to c__AnonStorey1.m (it seems a Mono file).
Any idea?
Debug your app step by step. You're using an anonymous delegate or lambda somewhere which causes a NULL ref exception.
The c__AnonStorey1 is a compiler generated class which captures your local variables.
(Using my crystal ball here to guess, because you are not showing any code)
Related
this is the first time I'm trying to write a request to you. Normaly I had could resolve most of the problems thanks to stackoverflow and others.
I developed an Xamarin.Forms App which runs on Android perfectly but when I try to deploy it to iOS (physical iPhone 8) it keeps breaking.
After searching for hours and trying diffrent things I hope someone can read out of the Code whats the matter...
I tried as well to set breakpoints in the appdelegate or first Page but after some seconds everthing breaks with this information:
2021-08-27 18:39:24.004 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 6
2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Processing: 'start profiler: no'
2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Profiler not loaded (disabled)
Loaded assembly: /private/var/containers/Bundle/Application/092BCD0C-2FC9-4F1B-A83E-29D87ACD245E/SHAPP.iOS.app/Xamarin.iOS.dll [External]
2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')
2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')
Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Xamarin.Forms.Core.dll [External]
2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')
2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')
Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/FFImageLoading.Platform.dll [External]
....
[0:] Failed to force load assembly /var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Forms9Patch.dll. Type:Forms9Patch.PopupLayerEffect. Exception: 'You must call Xamarin.Forms.Forms.Init(); prior to using this property.'. Callstack: ' at Xamarin.Forms.Device.get_PlatformServices () [0x00007] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:87
at Xamarin.Forms.Device.GetAssemblies () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:245
at Xamarin.Forms.DependencyService.Initialize () [0x00021] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:103
at Xamarin.Forms.DependencyService.Get[T] (Xamarin.Forms.DependencyFetchTarget fetchTarget) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:28
at Forms9Patch.Settings.ConfirmInitialization () [0x00008] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Models\Settings.cs:116
at Forms9Patch.PopupLayerEffect..cctor () [0x00000] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Effects\PopupLayerEffect.cs:19 '
...
[0:] An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147
at UIKit.UIResponder..ctor (Foundation.NSObjectFlag t) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIResponder.g.cs:74
at UIKit.UIView..ctor (Foundation.NSObjectFlag t) [0x00000] in
...
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
at SHAPP.iOS.Application.Main (System.String[] args) [0x00001] in C:\VisualCSharp\MyProjects\SHAPP\SHAPP.iOS\Main.cs:17
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '
Die App wurde beendet.
Thanks Jason and Saamer,
as you wrote i did try to fix that error prior to my request. But I could not find a way.
My AppDelegate looks like that:
using Foundation;
using Lottie.Forms.Platforms.Ios;
using UIKit;
namespace SHAPP.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Xamarin.Forms.Forms.Init();
Forms9Patch.iOS.Settings.Initialize(this);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
// ObjCRuntime.Class.ThrowOnInitFailure = false;
LoadApplication(new App());
//AnimationViewRenderer.Init();
return base.FinishedLaunching(app, options);
}
}
}
So nothing to special, I did even try to set the old Lottie Init, but it did not help. As well I tryed to cancel all nuget Lottiefiles in iOS and to reinstall them, afterwards I cleaned the projects and restartet the build, same error.
Only working thing is to completly cancel Lottieusage.
The Lottie-XAML I use look's like that:
<lottie:AnimationView
Animation="14525-plumbers.json"
AutoPlay="True"
RepeatCount="3"
RepeatMode="Restart"
CacheComposition="True"
HeightRequest="500"
VerticalOptions="Start"
HorizontalOptions="Center"
IsVisible="true"
/>
If I comment it out everything works fine.
The LottieAnimationfile is in my RessourcesFolder (BundledRessource) as well as in the main folder.
Folders iOS and LottieFiles
Gentlement any ideas, what could be wrong? Thanks in advance
As Jason mentioned, you need to add that line in the AppDelegate, as you can see in this example
But you have another error too as you can read the error message at the end of the StackTrace you shared:
An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147
What Lottie package are you using? Is it this one? Are you using the latest version?
You have to make sure that you add the iOS version of the Lottie package to the iOS project.
I created a new Xamarin Forms app for iOS in Visual Studio and added the following code in AppDelegate.cs referencing the ArcGIS runtime.
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize();
return base.FinishedLaunching(app, options);
}
This is the error I get with the Initialize method.
[0:] An error occurred: 'CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory assembly:<unknown assembly> type:<unknown type> member:(null)'. Callstack: ' at (wrapper managed-to-native) RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory(byte[],intptr&)
at RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.SetInstallDirectory (System.String installPath) <0x138775060 + 0x00010> in <2a33546a5b934b588629d4e33895c554>:0
at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.InitNative () <0x1387748c8 + 0x00004> in <2a33546a5b934b588629d4e33895c554>:0
at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize () <0x138774538 + 0x00042> in <2a33546a5b934b588629d4e33895c554>:0
at App1.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00013] in C:\Users\Chris\Documents\OnScene Xplorer\App1\App1.iOS\AppDelegate.cs:33
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
at App1.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\Chris\Documents\OnScene Xplorer\App1\App1.iOS\Main.cs:17
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '
Per Reflector, it's attempting to make a call into a native method using DllImport.
[DllImport("__Internal")]
private static extern void CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory([In, Out, MarshalAs(UnmanagedType.LPArray)] byte[] installPath, out IntPtr outErrorHandle);
I checked the deployment folder on my iPhone. There is a native framework coming in from Nuget and it is making it onto the iPhone. It appears to be the target of the native call. In my UWP app, 2 dlls (runtimecore.dll and runtimecorenet.dll) appear to be the target of the native call.
[0:] File: /private/var/containers/Bundle/Application/5A23D747-9648-4727-8677-FB4E036F0343/App6.iOS.app/Frameworks/ArcGIS-arm64.framework/_CodeSignature/CodeResources
[0:] File: /private/var/containers/Bundle/Application/5A23D747-9648-4727-8677-FB4E036F0343/App6.iOS.app/Frameworks/ArcGIS-arm64.framework/ArcGIS-arm64
[0:] File: /private/var/containers/Bundle/Application/5A23D747-9648-4727-8677-FB4E036F0343/App6.iOS.app/Frameworks/ArcGIS-arm64.framework/Info.plist
I also see this in the verbose build output:
3>MtouchExtraArgs = --framework:"${ProjectDir}/framework/ArcGIS-arm64.framework" --dynamic-symbol-mode=code
...
3>Task "AssignLinkMetadata" (TaskId:169)
3> Task Parameter:
3> Items=
3> C:\Users\Chris\.nuget\packages\esri.arcgisruntime.runtimes.ios\100.10.0\buildTransitive\Xamarin.iOS10\..\..\framework\ArcGIS-arm64.framework\ArcGIS-arm64
3> CopyToOutputDirectory=PreserveNewest
3> Link=framework\ArcGIS-arm64.framework\ArcGIS-arm64
3> C:\Users\Chris\.nuget\packages\esri.arcgisruntime.runtimes.ios\100.10.0\buildTransitive\Xamarin.iOS10\..\..\framework\ArcGIS-arm64.framework\Info.plist
3> CopyToOutputDirectory=PreserveNewest
3> Link=framework\ArcGIS-arm64.framework\Info.plist (TaskId:169)
3>Done executing task "AssignLinkMetadata". (TaskId:169)
I've read that native calls in iOS are static have to be built/compiled into the app. Do you know how I can check that this is happening correctly? Any idea what is going wrong with this native call?
Any help would be GREATLY appreciated. I would very much like to use my iPhone without a Mac to do dev on this project. Also don't want to commit to a Mac and then find the same problem!
Here is the stack
System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) MonoTouch.CoreGraphics.CGContext:CGContextDrawPDFPage (intptr,intptr)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.
at MonoTouch.CoreGraphics.CGContext.DrawPDFPage (MonoTouch.CoreGraphics.CGPDFPage page) [0x00000] in :0
at Neva.PdfViewer.PageContentView.Draw (MonoTouch.CoreGraphics.CGContext context) [0x00000] in :0
at Neva.PdfViewer.PageContentTile.DrawInContext (MonoTouch.CoreGraphics.CGContext ctx) [0x00000] in :0 [7.1.1]
While we were not able to recreate this problem in QA or unit testing, this exception randomly happens on AppStore distributed installations.
Looking at DrawPDFPage in CGContext
public void DrawPDFPage (CGPDFPage page)
{
CGContext.CGContextDrawPDFPage (this.handle, page.handle);
}
where CGContextDrawPDFPage is a P/Invoke function
[DllImport ("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")]
private static extern void CGContextDrawPDFPage (IntPtr c, IntPtr page);
doesn't give us any hint. The link above http://docs.xamarin.com/ios/about/limitations is not really helpful.
My question is, what could be causing such an exception? What are steps to debug and fix it?
This exception (System.ExecutionEngineException: Attempting to JIT compile method ...) should be 100% reproducible.
The fact that it isn't, points at something else (and probably worse): memory corruption of some sort.
However without some way to (at least randomly) reproduce it yourself, it's close to impossible to track down.
My initial suggestion would be to try to figure out if there's anything at all you can figure out in order to be able to create a test case yourself:
Does it only occur for a certain set of devices (only iPad 2 for instance)?
Does it only occur for a certain set of customers (only customers in Iceland for instance)?
Is the exception exactly the same every time, or does the P/Invoke / stack trace vary?
Is it a low-memory condition? Did the app get memory warnings prior to this occurring?
Are there any required steps in your app (i.e. if the user does X+Y it may crash, but if he does Y+X, then it never crashes)?
I am currently developing an application that needs to communicate with a MQTT server via a socket connection. As the System.Net.Sockets API tends to misbehave when switching from a WiFi network to a 3G network (and this happens quite a lot actually) I've decided to give the CFStream API a try. In doing so I've encountered several issues, as follows.
Creating a pair of streams with CreatePairWithSocketToHost crashes the application as soon as I call Open() on either one of the streams.
CFStream.CreatePairWithSocketToHost(GetEndPoint(), out mReadStream, out mWriteStream);
mReadStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mWriteStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mReadStream.Open();
mWriteStream.Open();
The crash occurs regardless of whether I call EnableEvents() or not. The exception is:
[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.CoreFoundation.CFException: The operation couldn’t be completed. Cannot allocate memory
at MonoTouch.CoreFoundation.CFStream.CheckError () [0x0000f] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFStream.cs:236
at MonoTouch.CoreFoundation.CFStream.Open () [0x00040] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFStream.cs:248
at TestCfNework.RootViewController.TestCreatePairToHost () [0x00041] in /Users/adrian/Projects/TestCfNework/TestCfNework/RootViewController.cs:79
at TestCfNework.RootViewController.ViewDidLoad () [0x00000] in /Users/adrian/Projects/TestCfNework/TestCfNework/RootViewController.cs:24
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:124
at TestCfNework.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0002e] in /Users/adrian/Projects/TestCfNework/TestCfNework/AppDelegate.cs:32
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 TestCfNework.Application.Main (System.String[] args) [0x00000] in /Users/adrian/Projects/TestCfNework/TestCfNework/Main.cs:17
Creating a pair of streams with CreatePairWithSocket by first creating and connecting a CFSocket allows for Open() to proceed without crashing, but CanAcceptBytesEvent is never fired, CanAcceptBytes() is always false and any write attempt fails with a timeout.
mSocket = new CFSocket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp,
CFRunLoop.Current);
mSocket.ConnectEvent += delegate {
Console.WriteLine("Socket connected");
CFStream.CreatePairWithSocket(mSocket, out mReadStream, out mWriteStream);
mReadStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mWriteStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mReadStream.Open();
mWriteStream.Open();
mWriteStream.CanAcceptBytesEvent += delegate {
Console.WriteLine("Write stream can now accept data");
};
mWriteStream.ErrorEvent += delegate {
Console.WriteLine(mWriteStream.GetError());
};
};
mSocket.Connect(GetEndPoint(), 0);
Creating a pair of streams using CreatePairWithPeerSocketSignature is the only one that actually produces a pair of streams that I can work with: opening does not crash and I am allowed to write to and read from respectively.
The API behaves this way both on the simulator and on the actual device. So, is this something I am doing wrong? Is it a MonoTouch issue? Is it a bug in the CFStream API itself?
MonoTouch version: 6.0.1.
XCode version: 4.5.
I wrote most the CFNetwork code in MonoMac / MonoTouch, so I should hopefully be able to help you with this :-)
Your code looks ok to me. It works fine with MonoMac (stand-alone Cocoa application on the Mac), but I see the same problem with MonoTouch. Opening the read stream sometimes works, sometimes not, opening the write stream always fails.
CFStream.CreatePairWithSocketToHost() calls CFStreamCreatePairWithSocketToCFHost().
After adding a new overloaded version:
public static void CreatePairWithSocketToHost (string host, int port,
out CFReadStream readStream,
out CFWriteStream writeStream)
which calls CFStreamCreatePairWithSocketToHost(), this is now working fine.
I just had a look at this and found the problem, will have a fix for it shortly.
About your second problem, the CFSocket API is hitting the same code path internally, so it's also affected by this bug.
To wake up the 3G network, you want to use:
http://iosapi.xamarin.com/?link=T%3aMonoTouch.ObjCRuntime.Runtime%2fM%2fStartWWAN
I'm getting the following exception from structure map - "Duplicate Objects detected for Instance d54e25dc-d19c-4d70-99d1-56bd2502d203 of Type ..."
The stack trace is:
at StructureMap.InstanceCache.Set(Type pluginType, Instance Instance, Object result) in c:\code\structuremap\Source\StructureMap\InstanceCache.cs:line 60
at StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance) in c:\code\structuremap\Source\StructureMap\BuildSession.cs:line 159
at StructureMap.BuildSession.<>c_DisplayClass3.<.ctor>b_1() in c:\code\structuremap\Source\StructureMap\BuildSession.cs:line 34
at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\code\structuremap\Source\StructureMap\BuildSession.cs:line 192
at StructureMap.BuildSession.GetInstance[T]() in c:\code\structuremap\Source\StructureMap\BuildSession.cs:line 78
This exception happens only from time to time and is very difficult to reproduce.
What I've found out so far:
Calling ObjectFactory.Container.GetInstance(type) will create a new BuildSession with a new non-static cache.
The call will reach BuildSession.CreateInstance(Type pluginType, Instance instance) and no instance is in the cache yet. (https://github.com/structuremap/structuremap/blob/master/Source/StructureMap/BuildSession.cs#L149-166)
Now we'll go on to _builder.Resolve(pluginType, instance, this);
Somewhere during Resolve() the object will get into the cache and later in CreateInstance we're saving it into the cache once again, receiving the exception.
That object is configured with Singleton lifecycle. The application is WCF service hosted in IIS.
Any help with finding the cause is appreciated.