maui: MAUI Blazor: System.IO.FileNotFoundException: '' on InitializeComponent()

Description

My Maui Blazor App on InitializeComponent() is throwing System.IO.FileNotFoundException: ‘’ on Visual Studio, even if I uncheck “Break when this exception type is thrown”

image

dotnet workload list

ID da carga de trabalho instalada      Versão do Manifesto      Origem da Instalação
------------------------------------------------------------------------------------
wasm-tools-net6                        7.0.3/7.0.100            VS 17.6.33513.286
maccatalyst                            16.2.1030/7.0.100        VS 17.6.33513.286
ios                                    16.2.1030/7.0.100        VS 17.6.33513.286
wasm-tools                             7.0.3/7.0.100            VS 17.6.33513.286
maui-android                           7.0.59/7.0.100           VS 17.6.33513.286
maui-windows                           7.0.59/7.0.100           VS 17.6.33513.286
maui-maccatalyst                       7.0.59/7.0.100           VS 17.6.33513.286
android                                33.0.26/7.0.100          VS 17.6.33513.286
maui-ios                               7.0.59/7.0.100           VS 17.6.33513.286

Use `dotnet workload search` para encontrar cargas de trabalho adicionais a serem instaladas.

Steps to Reproduce

Open the project in repository, run Debugging on Android device.

Link to public reproduction project repository

https://github.com/TonyHenrique/bug-2023-03-21

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 11.0 - API 30

Did you find any workaround?

No, because even if I uncheck “Break when this exception type is thrown” Visual Studio still stops at that line and I have to click the Continue button a few times.

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Duplicate of #7443

So I think the issue is related to satellite assemblies:

0x26 in System.Reflection.Assembly.Load
0x55 in System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly
0x4 in System.Resources.ManifestBasedResourceGroveler.InternalGetSatelliteAssembly
0x4D in System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly
0x31 in System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet
0xA4 in System.Resources.ResourceManager.InternalGetResourceSet
0x5A in System.Resources.ResourceManager.GetString
0x12B in System.SR.InternalGetResourceString
0xC in System.SR.GetResourceString
0x11 in System.Text.EncodingTable.GetDisplayName
0x30 in System.Text.EncodingTable.InternalGetCodePageDataItem
0xB9 in System.Text.EncodingTable.GetCodePageDataItem
0xF in System.Text.Encoding.GetDataItem
0x9 in System.Text.Encoding.get_WebName
0x1 in System.Xml.XmlTextReaderImpl.SwitchEncoding
0x235 in System.Xml.XmlTextReaderImpl.ParseXmlDeclaration
0xC8 in System.Xml.XmlTextReaderImpl.Read

In this case, the XmlReader just happens to hit the same problem as: https://github.com/dotnet/maui/issues/7443

Let me close this as duplicate, I’ll link to your example.

I don’t have a physical Android device but I’m paging Mr. @jonathanpeppers to see if perhaps this is familiar.

@jonathanpeppers - does anything in this call stack look like any known issue with XAML on a physical Android device? (Doesn’t repro on emulator, and a trivial app does not repro anywhere.)

Full repro app here: https://github.com/TonyHenrique/bug-2023-03-21

@Eilon, this only happens when I Run (Debug) on the physical Android device (HMD Global Nokia 5.3 (Android 12.0 - API 31)): System.IO.FileNotFoundException

This is what appears when I click “Show Call Stack” link button:

 	[External Code]	
 	0xC in MauiBlazorApp1.App.InitializeComponent at C:\Users\tonyv\source\repos\MauiBlazorApp1\MauiBlazorApp1\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\App.xaml.sg.cs:22,4	C#
>	0x9 in MauiBlazorApp1.App..ctor at C:\Users\tonyv\source\repos\MauiBlazorApp1\MauiBlazorApp1\App.xaml.cs:7,13	C#

If I click the “Show External Code” button:

0x26 in System.Reflection.Assembly.Load
0x55 in System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly
0x4 in System.Resources.ManifestBasedResourceGroveler.InternalGetSatelliteAssembly
0x4D in System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly
0x31 in System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet
0xA4 in System.Resources.ResourceManager.InternalGetResourceSet
0x5A in System.Resources.ResourceManager.GetString
0x12B in System.SR.InternalGetResourceString
0xC in System.SR.GetResourceString
0x11 in System.Text.EncodingTable.GetDisplayName
0x30 in System.Text.EncodingTable.InternalGetCodePageDataItem
0xB9 in System.Text.EncodingTable.GetCodePageDataItem
0xF in System.Text.Encoding.GetDataItem
0x9 in System.Text.Encoding.get_WebName
0x1 in System.Xml.XmlTextReaderImpl.SwitchEncoding
0x235 in System.Xml.XmlTextReaderImpl.ParseXmlDeclaration
0xC8 in System.Xml.XmlTextReaderImpl.Read
0xF9 in Microsoft.Maui.Controls.Xaml.XamlLoader.Load at C:\Users\tonyv\AppData\Local\SourceServer\b8d82a6a238382fded816d4ccb149e6e6cf6abd54f11376301554fd139ac2d82\XamlLoader.cs:61,5
	at C:\Users\tonyv\AppData\Local\SourceServer\b8d82a6a238382fded816d4ccb149e6e6cf6abd54f11376301554fd139ac2d82\XamlLoader.cs(61)
0x4 in Microsoft.Maui.Controls.Xaml.XamlLoader.Load at C:\Users\tonyv\AppData\Local\SourceServer\b8d82a6a238382fded816d4ccb149e6e6cf6abd54f11376301554fd139ac2d82\XamlLoader.cs:53,82
	at C:\Users\tonyv\AppData\Local\SourceServer\b8d82a6a238382fded816d4ccb149e6e6cf6abd54f11376301554fd139ac2d82\XamlLoader.cs(53)
0x2C in Microsoft.Maui.Controls.Xaml.XamlLoader.Load at C:\Users\tonyv\AppData\Local\SourceServer\b8d82a6a238382fded816d4ccb149e6e6cf6abd54f11376301554fd139ac2d82\XamlLoader.cs:49,4
	at C:\Users\tonyv\AppData\Local\SourceServer\b8d82a6a238382fded816d4ccb149e6e6cf6abd54f11376301554fd139ac2d82\XamlLoader.cs(49)
0x7 in Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml<MauiBlazorApp1.App> at C:\Users\tonyv\AppData\Local\SourceServer\3f69b6a15aebf4f4d7c19d7247b813d7b6b622013ea94bd88f053da69ea6513b\ViewExtensions.cs:37,4
	at C:\Users\tonyv\AppData\Local\SourceServer\3f69b6a15aebf4f4d7c19d7247b813d7b6b622013ea94bd88f053da69ea6513b\ViewExtensions.cs(37)
0xC in MauiBlazorApp1.App.InitializeComponent at C:\Users\tonyv\source\repos\MauiBlazorApp1\MauiBlazorApp1\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\App.xaml.sg.cs:22,4
0x9 in MauiBlazorApp1.App..ctor at C:\Users\tonyv\source\repos\MauiBlazorApp1\MauiBlazorApp1\App.xaml.cs:7,13
	at C:\Users\tonyv\source\repos\MauiBlazorApp1\MauiBlazorApp1\App.xaml.cs(7)
0x1B in System.Reflection.RuntimeConstructorInfo.InternalInvoke
0x35 in System.Reflection.ConstructorInvoker.InterpretedInvoke
0x4 in System.Reflection.ConstructorInvoker.InlinedInvoke
0x48 in System.Reflection.RuntimeConstructorInfo.Invoke
0x4D in Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor
0x47 in Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext,object>.VisitCallSiteMain
0x63 in Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache
0x52 in Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext,object>.VisitCallSite
0x27 in Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve
0x4C in Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor
0x51 in System.Collections.Concurrent.ConcurrentDictionary<System.Type,System.Func<Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope,object>>.GetOrAdd
0x1A in Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService
0x8 in Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService
0x2B in Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService at C:\Users\tonyv\AppData\Local\SourceServer\8250e6d757559e1b18f5cfe4af2a3f3acf8362a9bdc9c368836dd427d815d0af\MauiContext.cs:68,5
	at C:\Users\tonyv\AppData\Local\SourceServer\8250e6d757559e1b18f5cfe4af2a3f3acf8362a9bdc9c368836dd427d815d0af\MauiContext.cs(68)
0x2B in Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService at C:\Users\tonyv\AppData\Local\SourceServer\8250e6d757559e1b18f5cfe4af2a3f3acf8362a9bdc9c368836dd427d815d0af\MauiContext.cs:68,5
	at C:\Users\tonyv\AppData\Local\SourceServer\8250e6d757559e1b18f5cfe4af2a3f3acf8362a9bdc9c368836dd427d815d0af\MauiContext.cs(68)
0x2A in Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService
0x16 in Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService<Microsoft.Maui.IApplication>
0x57 in Microsoft.Maui.MauiApplication.OnCreate at C:\Users\tonyv\AppData\Local\SourceServer\eaa0a5e84c520fb29a25371407b0096d1a7da000257d60473a7ce9111058afc8\MauiApplication.cs:37,4
	at C:\Users\tonyv\AppData\Local\SourceServer\eaa0a5e84c520fb29a25371407b0096d1a7da000257d60473a7ce9111058afc8\MauiApplication.cs(37)
0x8 in Android.App.Application.n_OnCreate at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.App.Application.cs:1072,4
0x8 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at C:\Users\tonyv\AppData\Local\SourceServer\78db33ae6185378ba928d54bd50a3d4480de4ef6b888979ae362688171290d15\JNINativeWrapper.g.cs:22,5
	at C:\Users\tonyv\AppData\Local\SourceServer\78db33ae6185378ba928d54bd50a3d4480de4ef6b888979ae362688171290d15\JNINativeWrapper.g.cs(22)

image

Can you please try this on an real physical Android phone?

If I run the App on the emulator (Nexus 5X - API 31), the error does not occur, as you noticed:

image

Hi @TonyHenrique I cloned your app and ran it and did not see any exceptions at all. I ran the MauiBlazorApp1 project in the Android Emulator and it worked fine:

image

If you’re still seeing the exception, can you click “Show Call Stack” so that we can see more details about the exception you’re seeing?