Weird Xamarin.iOS bug only with Enable debug on (adhoc/release builds) - ios

I've two weird issues with Xamarin.iOS:
1) NavigationController.PushViewController does work correctly with Debug enabled and NOT with debug disabled.
2) With debug disabled the app crashes after about 60 seconds, but not crash log on the device.
First I noticed the difference between Debug and AdHoc build. But now when I use AdHoc build and turn on 'Enabling debug' it magically works, without further adjustments to settings. Debug symbols are removed and Debug info is set to None.
I saw two other similar questions on this forum and forums.xamarin from a couple of years ago with no answers. I tried different linker and compiler and GC settings on the project but they were not helpful.
Hope someone can help me out.

You can use one hack to get more information about the crash from a device. Since all your code is executable through mono runtime, you can easily catch lots of crashes by wrapping your UIAplication.Main function into a try-catch block, and save the exception string somewhere on the device.
in Main.cs
public class Application {
static void Main(string[] args) {
try {
UIApplication.Main(args: args, principalClassName: null, delegateClassName: typeof(AppDelegate).Name);
} catch (Exception e) {
// save e.ToString() somewhere
}
}
}

Related

Xamarin IOS debug, app crashes with no error

When I run app with debug from Visual Studio in IOS Emulator, app launches, shows splash screen and then crashes.
Visual Studio continue showing normal behavior like it is still attached to debug process and everything go according to plan.
When I launch that same app on emulator manually, it works perfectly.
Debug log always as this:
Loaded assembly:
/Users/admin/Library/Developer/CoreSimulator/Devices/40C63365-3924-44EA-9145-AAF5F59D170F/data/Containers/Bundle/Application/FED2C1CB-FD8E-441A-856C-66981DB384B5/WebtutorMobileX.iOS.app/Xamarin.iOS.dll
[External] Loaded assembly:
/Users/admin/Library/Developer/CoreSimulator/Devices/40C63365-3924-44EA-9145-AAF5F59D170F/data/Containers/Bundle/Application/FED2C1CB-FD8E-441A-856C-66981DB384B5/WebtutorMobileX.iOS.app/System.dll
[External] Loaded assembly:
/Users/admin/Library/Developer/CoreSimulator/Devices/40C63365-3924-44EA-9145-AAF5F59D170F/data/Containers/Bundle/Application/FED2C1CB-FD8E-441A-856C-66981DB384B5/WebtutorMobileX.iOS.app/Mono.Security.dll [External]
After that app crashes and nothing happens. Visual Studio stays in blessed ignorance.
No errors whatsoever.
This began after I upgraded to 4.7.0.1179 and XCode 11.6. Visual Studio 2019 16.6.5.
Changing iOS Linker settings to "Link Framework SDKs Only" has fixed it for me (if someone still has this problem in 2022).
VS for Mac 17.3.8 - XCode 14 - XF 5.0.0.2515
Put a try/catch block in the Main.cs file in the xamarin.ios project and a breakpoint in the catch block, it usually tells you what wrong in this kind of crash.
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
try
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
catch (Exception ex)
{
//Breakpoint here
}
}
}
Visual Studio Version 16.7.4 + Xamarin IOS 14.0, debug working again.

I'm having All Exceptions Breakpoint problems [duplicate]

After upgrading to Xcode 11.3, our app throws an exception when running on an iOS 13.3 device. The exception does not occur at the same place every time, and the log indicates the exception is coming from com.apple.CoreAnalytics (see below). The exception is only thrown once. And, the exception is NOT thrown when I run the app on the simulator. Thanks in advance for your thoughts and ideas!
Sometimes Apple's frameworks use exceptions as an internal messaging technique. They probably shouldn't do that, but the frameworks contain a lot of old code that doesn't always follow best practices. There is no harm done, because the framework, having thrown the exception, also catches it, which is why you run fine if the app just runs without the debugger. But if you run from Xcode and you have set an Exception Breakpoint, you will pause after the throw but before the catch. It looks like that's what's happening. So just remove that breakpoint.

Intermittent Xamarin.iOS crash with no exception thrown

I have created a Xamarin.Forms barcode scanning app with Android and iOS projects. The Android build appears to run fine, but the iOS build occasionally crashes and I am struggling to pin down the cause, as no crash log is produced and no exception is reported in the application output.
Under heavy load (non-stop barcode scanning) the app crashes after typically 200 or 300 barcodes have been scanned.
I am puzzled how such a crash can occur, leaving absolutely no evidence of its cause. Is there somewhere else I should be looking for the evidence, apart from within Xcode's Devices window? Shouldn't I expect an exception to be reported in the application output, while debugging?
I have implemented logging handlers for AppDomain.CurrentDomain.UnhandledException and TaskScheduler.UnobservedTaskException but they don't appear to be called. Is there some other way I can instrument my code to trap the cause of this crash?
Many thanks for your advice,
Tim
To get some output I always hit the continue button in visual studio debugger. The application stops, and for some reason I can see an exception in the output. Hope this helps.

Xamarin Forms, MS Azure Crashes not working on iOS

I followed this link and added Analytics and Crashes correctly to Android but in iOS only Analytics added correctly. for checking if Crashes is working on iOS, I created some crashes like so:
1.
int a = 0;
int b = 2 / a;
2.
throw new Exception("jiiiiz");
3.
Crashes.GenerateTestCrash();
but non of them are reported to azure crashes panel, I also check if an error happen in next session app is opened but it's always false:
protected override async void OnAppearing()
{
base.OnAppearing();
var a = Crashes.HasCrashedInLastSession;
Debug.WriteLine($"Crashed?? {a}"); // is always false
}
As Mobile Center Crashes documentation mentioned about Troubleshooting:
Right now crash reports are only visible if they can be symbolicated. For that to happen the proper symbols (dSYM) need to be uploaded. There will be a UI available later that shows which symbols are missing and how to find them.
Make sure the app doesn't crash on startup, as the SDK wouldn't have time to send the crash report. This is a limitation for any 3rd party crash reporting service.
For how to provide symbols for your app, you could refer to Uploading symbols.

App crashes before debugger can connect

I've got an app that crashes even before the debugger can connect.
I placed a break point on the first line of main(). (I added an NSLog statement as very first statement in main() and set the break point there.
The app seems to start. The main screen with some ui elements becomes visible on the screen. Then it disappears.
There is no crash log found on the devices.
Xcode message:
Could not launch "appname"
process launch failed: failed to get the task for process xyz
Debugging is enabled of course.
The same for the profiler Instruments.
Code signing works fine so that the app can be deployed to the devices.
(Same for enterprise distribution. And the app validates for store submission.)
It does work on the simulator though.
The app used to work fine. I was just about to build it for the store. For final tests on iOS 8.1 I upgraded to Xcode 6.1 with SDK 8.1. But the problem did not occur directly after the upgrade. It worked just fine.
Then it crashed when building for release for enterprise distribution.
The AppStore build crashed in the same manner (according to Apple, the app was rejected of course.)
But it ran nicely in debug modes.
Now I was trying whether compiler options for optimization may make all the difference and I was trying to build in release mode with debugging enabled etc and end up with a debug build crashing as well. (No optimization in debug).
So it may well be that the migration to Xcode 6.1 did cause it but the problem may have come effective only after Xcode cleaned and rebuild the project in response to changes to compiler settings for code optimization.
Sorry for the long text. I tried to put everything in that may be of importance.
Reason is most likely some incompatibility of Crackify and iOS 8.1.
Therefore it may be of interest for others, altough my problem along with these symptoms may be very special.
Very early within AppDelegate didFinishLaunchingWithOptions we have had the following statement.
if ([Crackify isCracked] || [self isCertificateUnvalid])
exit(173);
That, as such, is not really well designed. The app is just terminated rather than any error message displayed to the user. Thus, it appears as if the app has crashed. But it has not crashed and therefore no crashlog is provided.
For reasons which I don't yet understand and which may not be related to this error, my debugger did not manage to hook up into the executed app. Once that was overcome (suddenly the debugger worked without any changes made to any of the debugging related settings) the error was found rather quickly.
This is Crackify: https://github.com/itruf/crackify
Within Crackify it was this code sniplet that caused the problem:
static NSString *str2 = #"ResourceRules.plist";
BOOL fileExists3 = [manager fileExistsAtPath:([NSString stringWithFormat:#"%#/%#", bundlePath, str2])];
if (!fileExists3) {
return YES;
}
For reasons that I did not further investigate, the file, that is tested here, apparently does not exist in iOS 8.1 any more.

Resources