maui
maui copied to clipboard
Unable to load font 'monospace'
Description
I'm using the 'monospace' font in my xamarin forms app. When migrating to maui, it looks like it does not work anymore
Steps to Reproduce
- Create a maui app for android
- Create a label using the 'monospace' font
- Run the app
<Label FontFamily="monospace" Text="Hello world" />
Link to public reproduction project repository
...
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
...
Did you find any workaround?
No response
Relevant log output
[Microsoft.Maui.FontManager] [Warning] Unable to load font 'monospace' from assets.Java.Lang.RuntimeException: Font asset not found monospace
[Microsoft.Maui.FontManager] at Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:line 12890
[Microsoft.Maui.FontManager] at Java.Interop.JniPeerMembers.JniStaticMethods.InvokeObjectMethod(String encodedMember, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniStaticMethods.cs:line 95
[Microsoft.Maui.FontManager] at Android.Graphics.Typeface.CreateFromAsset(AssetManager mgr, String path) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net6.0/android-33/mcw/Android.Graphics.Typeface.cs:line 613
[Microsoft.Maui.FontManager] at Microsoft.Maui.FontManager.LoadTypefaceFromAsset(String fontfamily, Boolean warning) in D:\a\_work\1\s\src\Core\src\Fonts\FontManager.Android.cs:line 122
[Microsoft.Maui.FontManager] --- End of managed Java.Lang.RuntimeException stack trace ---
[Microsoft.Maui.FontManager] java.lang.RuntimeException: Font asset not found monospace
[Microsoft.Maui.FontManager] at android.graphics.Typeface.createFromAsset(Typeface.java:1044)
[Microsoft.Maui.FontManager] at crc6452ffdc5b34af3a0f.NavigationViewFragment.n_onCreateView(Native Method)
[Microsoft.Maui.FontManager] at crc6452ffdc5b34af3a0f.NavigationViewFragment.onCreateView(NavigationViewFragment.java:39)
[Microsoft.Maui.FontManager] at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2995)
[Microsoft.Maui.FontManager] at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:523)
[Microsoft.Maui.FontManager] at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
[Microsoft.Maui.FontManager] at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
[Microsoft.Maui.FontManager] at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764)
[Microsoft.Maui.FontManager] at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701)
[Microsoft.Maui.FontManager] at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:488)
[Microsoft.Maui.FontManager] at android.os.Handler.handleCallback(Handler.java:942)
[Microsoft.Maui.FontManager] at android.os.Handler.dispatchMessage(Handler.java:99)
[Microsoft.Maui.FontManager] at android.os.Looper.loopOnce(Looper.java:201)
[Microsoft.Maui.FontManager] at android.os.Looper.loop(Looper.java:288)
[Microsoft.Maui.FontManager] at android.app.ActivityThread.main(ActivityThread.java:7898)
[Microsoft.Maui.FontManager] at java.lang.reflect.Method.invoke(Native Method)
[Microsoft.Maui.FontManager] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
[Microsoft.Maui.FontManager] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Are you trying in a specific device or also emulators?
Emulator for now
Happening on Windows 10 as well:
`Microsoft.Maui.FontRegistrar: Warning: Unable to load font 'Roboto'.
System.IO.FileNotFoundException: Native font with the name Roboto-Black.tff was not found. at Microsoft.Maui.FontRegistrar.LoadNativeAppFont(String font, String filename, String alias) at Microsoft.Maui.FontRegistrar.GetFont(String font)`
Hi @tranb3r. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This happens to the base .net MAUI 7 project. Add any font to the base fonts folder, add it to the MauiProgram.cs file and it fails.
Here is a repro : https://github.com/tranb3r/Issues/tree/main/MauiAppFontMonospace Please note that there is an exception, but the label is actually displayed correctly with the correct font.
Here is a repro : https://github.com/tranb3r/Issues/tree/main/MauiAppFontMonospace Please note that there is an exception, but the label is actually displayed correctly with the correct font.
Could you share the Exception StackTrace?
Hi @tranb3r. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@jsuarezruiz The stack trace is in the description of this issue.