Weird malfunction with Enabling debug disabled (adhoc/release builds)

JorgenJorgen USMember ✭✭

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 from a couple of years ago with no answers. Hope someone can help me out. I'm getting nuts here.

Best Answer

  • JorgenJorgen US ✭✭
    Accepted Answer

    To answer my own question: there was some other view pushed on to the navigationcontroller which caused this error to occur. This didn't happen in debug for some reason and also didn't generate a good crash report. I managed to find it by using a tip from someone on stackoverflow:
    `

            try {
                //UIApplication.Main(args: args, principalClassName: null, delegateClassName: typeof(AppDelegate).Name);
                // 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) {
                // save e.ToString() somewhere
                var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "crash.txt");
                System.IO.File.WriteAllText(filename, "Main " + ex.ToString());
            }
    

    `

    Then in the first view of your app when you restart the app (only in debug):
    `
    var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "crash.txt");
    if (File.Exists(filename))
    {
    String bug = string.Empty;
    using (StreamReader sr = new StreamReader(filename))
    bug = sr.ReadToEnd();

                    ShowSimpleAlert("Error", bug, "OK"); 
                }
    

    `

Answers

  • JorgenJorgen USMember ✭✭
    Accepted Answer

    To answer my own question: there was some other view pushed on to the navigationcontroller which caused this error to occur. This didn't happen in debug for some reason and also didn't generate a good crash report. I managed to find it by using a tip from someone on stackoverflow:
    `

            try {
                //UIApplication.Main(args: args, principalClassName: null, delegateClassName: typeof(AppDelegate).Name);
                // 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) {
                // save e.ToString() somewhere
                var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "crash.txt");
                System.IO.File.WriteAllText(filename, "Main " + ex.ToString());
            }
    

    `

    Then in the first view of your app when you restart the app (only in debug):
    `
    var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "crash.txt");
    if (File.Exists(filename))
    {
    String bug = string.Empty;
    using (StreamReader sr = new StreamReader(filename))
    bug = sr.ReadToEnd();

                    ShowSimpleAlert("Error", bug, "OK"); 
                }
    

    `

Sign In or Register to comment.