Force break or trace on Exception

SolomonFriedSolomonFried USMember ✭✭
edited June 2018 in Xamarin.iOS

My Xamarin.Forms app is getting an ArgumentNullException on startup. If I ignore it, it continues anyway but is unstable.
The exception is always displayed right after LoadApplication but is being thrown from somewhere deeper in the call stack

My problem is that if I set Exception Settings to "Break when this exception is throw:", it is ignored.
Is there a way to turn on stack tracing and log it somewhere?
When the exception is thrown it shows this at the top of the stack
0x3 in UIKit.UIFont._FromDescriptor at /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIFont.g.cs:104,5 C#

I suspect there is a font issue with custom fonts. When I remove or misspell my custom fonts in info.plist, then the exception is not thrown.
When the exception is throw, the app continues and the fonts are clearly being used.

UPDATE!!!
I have tried to manually load the fonts into UIKit. I am getting an ArgumentNullException on this statement

        var f1 = CGFont.CreateWithFontName("Fonts/MyLayoutControlFonts.otf");

The otf file definitely exists in the Resources folder and is included as a Bundled Resource. (I also tried as an Embedded resource)

Thank you

Posts

  • ColeXColeX Member, Xamarin Team Xamurai
    edited June 2018

    The parameter you passed in CreateWithFontName should be a PostScript or full name. Refer to CGFontCreateWithFontName

    Here you set it as font path ,so the font can't be created.

  • SolomonFriedSolomonFried USMember ✭✭

    @ColeX said:
    The parameter you passed in CreateWithFontName should be a PostScript or full name. Refer to CGFontCreateWithFontName

    Here you set it as font path ,so the font can't be created.

    Thanks for that.

    I did change the name to just the font name and the CreateWithFontName does not abend.
    But I am back to my original issue.

    I have an app with custom fonts. When I add the fonts to my Info.plist, I get an ArgumentNullException on startup in AppDelegate. If I remove the fonts form the list or even misspell them, then the exception does not occur.

    As an aside, this app works fine in Android and UWP.

    I was trying to load the fonts in code instead of having it load automatically and that is how I came upon the CreateWithFontName. However, I can only use that with fonts in Info.plist (or I assume with any font registered on the machine).

    Do you know if there is a way for me to load fonts without including then in Info.plist.

    Thank you

  • SolomonFriedSolomonFried USMember ✭✭

    Update:
    After a week if tracking down an ArgumentNullException in my app that I suspected was related to my custom fonts,
    I finally found that the Button containing the font had a Style with a FontAttribute set to BOLD.
    I removed that attribute and the exception is no longer being thrown.

    Not sure if this is an iOS or Xamarin issue. The app works fine on UWP and Android.

Sign In or Register to comment.