Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOT - Cannot use System.Reflection on type named AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage #78638

Closed
sencagri opened this issue Nov 11, 2022 · 23 comments · Fixed by #83273
Assignees
Milestone

Comments

@sencagri
Copy link

Description

I have published a .NET Maui app it is working on emulators but not working on real devices. By the way, I have tested 5 different real device.

When trimming and AOT is disabled it works but incredibly slow and sluggish.

There is a apk file I have uploaded for testing, you can download it to your devices and emulators also.
https://aktifbarkod.com/d just go and download apk file. ( There is a only one apk file )

The only log output I can find is below from a real device:

android.runtime.JavaProxyThrowable: System.TypeLoadException: Could not load type AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage while decoding custom attribute: (null)
   at System.Reflection.CustomAttribute.GetCustomAttributesBase(ICustomAttributeProvider , Type , Boolean )
   at System.Reflection.CustomAttribute.GetCustomAttributes(ICustomAttributeProvider , Type , Boolean )
   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType)
   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes(Assembly , Type )
   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[XamlResourceIdAttribute](Assembly )
   at Microsoft.Maui.Controls.Xaml.XamlResourceIdAttribute.GetTypeForPath(Assembly assembly, String path)
   at Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(Uri value, String resourcePath, Assembly assembly, IXmlLineInfo lineInfo)
   at AktifBarkod.AktifPOS.Mobil.App.InitializeComponent()
   at AktifBarkod.AktifPOS.Mobil.App..ctor()
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type )
   at System.Collections.Concurrent.ConcurrentDictionary2[[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type , Func`2 )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type )
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider , Type )
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IApplication](IServiceProvider )
   at Microsoft.Maui.MauiApplication.OnCreate()
   at Android.App.Application.n_OnCreate(IntPtr , IntPtr )
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
 at crc6488302ad6e9e4df1a.MauiApplication.n_onCreate(Native Method)
 at crc6488302ad6e9e4df1a.MauiApplication.onCreate(MauiApplication.java:28)
 at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1193)
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6975)
 at android.app.ActivityThread.access$1500(ActivityThread.java:257)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1982)
 at android.os.Handler.dispatchMessage(Handler.java:106)
 at android.os.Looper.loop(Looper.java:236)
 at android.app.ActivityThread.main(ActivityThread.java:8037)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

Real device

video_2022-11-11_21-27-24.mp4

Emulator

2022-11-11.21-37-47.mp4

PS:

Steps to Reproduce

Link to public reproduction project repository

This is a private repo.

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

All android versions

Did you find any workaround?

no

Relevant log output

No response

@VictorCanovasA
Copy link

Same issue here. I have updated to .net 7 to see if it solves the problem but apk still crashes

@jsuarezruiz
Copy link

cc @jonathanpeppers

@Taiizor
Copy link

Taiizor commented Nov 17, 2022

Try without Turkish characters AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage.

@alrit-solutions
Copy link

I am getting the same issue with my .net Maui signed app. Has there been any other feedback or way around this?

@sencagri
Copy link
Author

Try without Turkish characters AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage.

That seems work for my case. Thanks

@Taiizor
Copy link

Taiizor commented Nov 21, 2022

Try without Turkish characters AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage.

That seems work for my case. Thanks

nP

@jonathanpeppers jonathanpeppers changed the title Signed apks not working on real devices but working on emulators AOT - Cannot use System.Reflection on type named AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage Nov 21, 2022
@jonathanpeppers
Copy link
Member

Moving this to dotnet/runtime, for them to look at it.

@jonathanpeppers jonathanpeppers transferred this issue from dotnet/maui Nov 21, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 21, 2022
@ghost
Copy link

ghost commented Nov 21, 2022

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I have published a .NET Maui app it is working on emulators but not working on real devices. By the way, I have tested 5 different real device.

When trimming and AOT is disabled it works but incredibly slow and sluggish.

There is a apk file I have uploaded for testing, you can download it to your devices and emulators also.
https://aktifbarkod.com/d just go and download apk file. ( There is a only one apk file )

The only log output I can find is below from a real device:

android.runtime.JavaProxyThrowable: System.TypeLoadException: Could not load type AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage while decoding custom attribute: (null)
   at System.Reflection.CustomAttribute.GetCustomAttributesBase(ICustomAttributeProvider , Type , Boolean )
   at System.Reflection.CustomAttribute.GetCustomAttributes(ICustomAttributeProvider , Type , Boolean )
   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType)
   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes(Assembly , Type )
   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[XamlResourceIdAttribute](Assembly )
   at Microsoft.Maui.Controls.Xaml.XamlResourceIdAttribute.GetTypeForPath(Assembly assembly, String path)
   at Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(Uri value, String resourcePath, Assembly assembly, IXmlLineInfo lineInfo)
   at AktifBarkod.AktifPOS.Mobil.App.InitializeComponent()
   at AktifBarkod.AktifPOS.Mobil.App..ctor()
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type )
   at System.Collections.Concurrent.ConcurrentDictionary2[[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(Type , Func`2 )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type )
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider , Type )
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IApplication](IServiceProvider )
   at Microsoft.Maui.MauiApplication.OnCreate()
   at Android.App.Application.n_OnCreate(IntPtr , IntPtr )
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
 at crc6488302ad6e9e4df1a.MauiApplication.n_onCreate(Native Method)
 at crc6488302ad6e9e4df1a.MauiApplication.onCreate(MauiApplication.java:28)
 at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1193)
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6975)
 at android.app.ActivityThread.access$1500(ActivityThread.java:257)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1982)
 at android.os.Handler.dispatchMessage(Handler.java:106)
 at android.os.Looper.loop(Looper.java:236)
 at android.app.ActivityThread.main(ActivityThread.java:8037)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

Real device

video_2022-11-11_21-27-24.mp4

Emulator

2022-11-11.21-37-47.mp4

PS:

Steps to Reproduce

Link to public reproduction project repository

This is a private repo.

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

All android versions

Did you find any workaround?

no

Relevant log output

No response

Author: sencagri
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

@SamMonoRT
Copy link
Member

cc @ivanpovazan @jandupej : please investigate.

@SamMonoRT SamMonoRT added this to the 8.0.0 milestone Dec 2, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 2, 2022
@ivanpovazan
Copy link
Member

@sencagri could you please provide versions of dotnet and MAUI you were using?

Same issue here. I have updated to .net 7 to see if it solves the problem but apk still crashes

@VictorCanovasA does it crash with the same exception?

@sencagri
Copy link
Author

sencagri commented Dec 7, 2022

image

All possible combinations tested.

@alrit-solutions
Copy link

I managed to get this working in the end by removing Android SDKs and re-downloading/installing them. Had to recreate the device images again for the emulator. Also went back to .net 6.
image

@ivanpovazan
Copy link
Member

ivanpovazan commented Dec 8, 2022

@alrit-solutions thank you for the update.

Does this mean there is no crash on a device with original naming:AktifBarkod.AktifPOS.Mobil.EkranDiğer.Ana.AnaPage as initially reported?

@sencagri
Copy link
Author

sencagri commented Dec 8, 2022

We are not working together.

@ivanpovazan
Copy link
Member

@sencagri I see, thank you for your input. I will try to reproduce the issue and come back to you.

@sencagri
Copy link
Author

sencagri commented Dec 8, 2022

@sencagri I see, thank you for your input. I will try to reproduce the issue and come back to you.

Hey thanks.
Just to inform you. We have changed all the namespace characters to ASCII. Now, this is a low priority bug for us.
But It would be good to get a warning on compile time or a docs warning for others not to use non ascii characters in their projects for now.

@espenrl
Copy link
Contributor

espenrl commented Dec 20, 2022

It seems to be an issue specific to XAML. I have types in my MAUI project with Norwegian letter å, but only those used in XAML causes this problem for me. Other ones work fine. I had to rename a viewmodel and some pocos which where being databound in XAML.

@jonathanpeppers
Copy link
Member

@espenrl can you try disabling XAML compilation?

https://learn.microsoft.com/en-us/dotnet/maui/xaml/xamlc?view=net-maui-7.0#disable-compilation

If that solves your problem, we should move this back to dotnet/maui.

@espenrl
Copy link
Contributor

espenrl commented Dec 20, 2022

These results are from release builds deployed by cable through latest VS Preview to a Samsung S22.

With XAML compilation set to skip at assembly level the app crashes at startup. And I don't get an error message because of the release build.

With XAML compilation set to skip at the page level I get a different error message. Please see the exceptions below.

namespace Mdir.Views;

public sealed partial class VerneområdePage : ContentPage
{
    public VerneområdePage(VerneområdeViewModel viewModel)
    {
        InitializeComponent();
        BindingContext = viewModel;
    }
}

Before applying XAML compilation skip.

System.TypeLoadException: Could not resolve type with token 0100033b from typeref (expected class 'Mdir.Views.VerneområdeViewModel' in assembly '')
   at Mdir.Views.VerneområdePage..ctor(VerneområdeViewModel viewModel)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type )
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.Controls.Routing.TypeRouteFactory.GetOrCreate(IServiceProvider services)
   at Microsoft.Maui.Controls.Routing.GetOrCreateContent(String route, IServiceProvider services)
   at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(String route, ShellRouteParameters queryData, IServiceProvider services, Boolean isLast, Boolean isPopping)
   at Microsoft.Maui.Controls.ShellSection.GoToAsync(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, Nullable`1 animate, Boolean isRelativePopping)
   at Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync(ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest)

With [XamlCompilation (XamlCompilationOptions.Skip)] at page level.

System.TypeLoadException: Could not load type Mdir.Views.VerneområdePage while decoding custom attribute: (null)
   at System.Reflection.CustomAttribute.GetCustomAttributesBase(ICustomAttributeProvider , Type , Boolean )
   at System.Reflection.CustomAttribute.GetCustomAttributes(ICustomAttributeProvider , Type , Boolean )
   at System.Attribute.GetCustomAttributes(Assembly , Type )
   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes(Assembly , Type )
   at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[XamlResourceIdAttribute](Assembly )
   at Microsoft.Maui.Controls.Xaml.XamlResourceIdAttribute.GetResourceIdForType(Type type)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.GetXamlForType(Type type, Object instance, Boolean& useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[VerneområdePage](VerneområdePage view, Type callingType)
   at Mdir.Views.VerneområdePage.InitializeComponent()
   at Mdir.Views.VerneområdePage..ctor(VerneområdeViewModel viewModel)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags , Binder , Object[] , CultureInfo )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite , RuntimeResolverContext )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type , ServiceProviderEngineScope )
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type )
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.Controls.Routing.TypeRouteFactory.GetOrCreate(IServiceProvider services)
   at Microsoft.Maui.Controls.Routing.GetOrCreateContent(String route, IServiceProvider services)
   at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(String route, ShellRouteParameters queryData, IServiceProvider services, Boolean isLast, Boolean isPopping)
   at Microsoft.Maui.Controls.ShellSection.GoToAsync(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, Nullable`1 animate, Boolean isRelativePopping)
   at Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync(ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest)

@jonathanpeppers
Copy link
Member

@espenrl it looks like you can disable XamlC completely with:

<PropertyGroup>
  <MauiXamlCValidateOnly>true</MauiXamlCValidateOnly>
</PropertyGroup>

That should prevent it from writing assemblies with Mono.Cecil at all. Does that change anything?

@espenrl
Copy link
Contributor

espenrl commented Dec 22, 2022

I tried it and the app still crashes upon startup.

@Phantom-KNA
Copy link

Phantom-KNA commented Jan 3, 2023

If you are using compile to call change from compile to skip
XamlCompilation (XamlCompilationOptions.Skip)]
Some files may need to be changed in .csproj.
<PublishTrimmed>False</PublishTrimmed> <RunAOTCompilation>False</RunAOTCompilation>

I had the same error this is how I was able to fix it.

@ivanpovazan
Copy link
Member

Thank you all for the provided input.
After investigating it does not seem to be related to XamlC, but instead to the AOT image.
I have created a smaller example which reproduces the issue.

The repro steps are as follows..

Dotnet and MAUI versions:

  • dotnet 7.0.100
  • maui 7.0.52/7.0.100 SDK 7.0.100

Create, build and run the following application:

  1. Create a MAUI application:
    dotnet new maui -n ReproIssue78638
  2. Add the following types to the MauiProgram.cs:
[AttributeUsage(AttributeTargets.Class)]
public class TestingAttribute : Attribute
{
	public Type Type {get; private set;}
	public TestingAttribute(Type type)
	{
		Type = type;
	}
}

[Testing(typeof(EkranDiğer))]
public class ATestingClass
{
	public ATestingClass(){}
}

public class EkranDiğer{}
  1. Adjust the CreateMauiApp method in MauiProgram.cs by adding:
public static MauiApp CreateMauiApp()
{
	var attr = (TestingAttribute) Attribute.GetCustomAttribute(typeof(ATestingClass), typeof (TestingAttribute));
	Console.WriteLine($"CreateMauiApp started {attr.Type}");

	var builder = MauiApp.CreateBuilder();
	...
  1. Build the application and run on a device:
    dotnet publish -c Release -t:Run -f net7.0-android -bl
  2. Inspect the log with
    adb logcat > log.txt
... log.txt:
01-13 14:41:26.202 24860 24860 E AndroidRuntime: android.runtime.JavaProxyThrowable: System.TypeLoadException: Could not load type ReproIssue78638.EkranDiğer while decoding custom attribute: (null)
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at System.Reflection.CustomAttribute.GetCustomAttributesBase(ICustomAttributeProvider , Type , Boolean )
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at System.Reflection.CustomAttribute.GetCustomAttributes(ICustomAttributeProvider , Type , Boolean )
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at System.Attribute.GetAttr(ICustomAttributeProvider , Type , Boolean )
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at System.Attribute.GetCustomAttribute(MemberInfo , Type )
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at ReproIssue78638.MauiProgram.CreateMauiApp()
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at ReproIssue78638.MainApplication.CreateMauiApp()
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at Microsoft.Maui.MauiApplication.OnCreate()
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at Android.App.Application.n_OnCreate(IntPtr , IntPtr )
01-13 14:41:26.202 24860 24860 E AndroidRuntime:    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at crc6488302ad6e9e4df1a.MauiApplication.n_onCreate(Native Method)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at crc6488302ad6e9e4df1a.MauiApplication.onCreate(MauiApplication.java:28)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1208)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6986)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at android.app.ActivityThread.access$1700(ActivityThread.java:274)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2093)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:233)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:8010)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
01-13 14:41:26.202 24860 24860 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

I also confirmed that the problem is not present on iOS platforms.

  • Built and executed with: dotnet publish -c Release -t:Run -f net7.0-ios -r ios-arm64 -bl
  • The app successfully starts up and prints: CreateMauiApp started ReproIssue78638.EkranDiğer

I will continue investigating.

lambdageek added a commit to lambdageek/runtime that referenced this issue Mar 10, 2023
The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes dotnet#82187
Fixes dotnet#78638
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 10, 2023
@lambdageek lambdageek assigned lambdageek and unassigned ivanpovazan Mar 10, 2023
github-actions bot pushed a commit that referenced this issue Mar 11, 2023
The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes #82187
Fixes #78638
lambdageek added a commit to lambdageek/mono that referenced this issue Mar 11, 2023
The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes dotnet/runtime#82187
Fixes dotnet/runtime#78638
github-actions bot pushed a commit to mono/mono that referenced this issue Mar 11, 2023
The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes dotnet/runtime#82187
Fixes dotnet/runtime#78638
akoeplinger pushed a commit to mono/mono that referenced this issue Mar 13, 2023
Backport of dotnet/runtime#83273 to mono/mono `main`

The C standard does not specify whether `char` is signed or unsigned, it is implementation defined.

Apparently Android aarch64 makes a different choice than other platforms (at least macOS arm64 and Windows x64 give different results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime to optimize class name lookup.  As a result, classes whose names include UTF-8 continuation bytes (with the high bit = 1) will hash differently in the AOT compiler and on the device.

Contributes to dotnet/runtime#82187 
Contributes to dotnet/runtime#78638
akoeplinger pushed a commit to mono/mono that referenced this issue Mar 13, 2023
Backport of dotnet/runtime#83273 to mono/mono `2020-02`

The C standard does not specify whether `char` is signed or unsigned, it is implementation defined.

Apparently Android aarch64 makes a different choice than other platforms (at least macOS arm64 and Windows x64 give different results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime to optimize class name lookup.  As a result, classes whose names include UTF-8 continuation bytes (with the high bit = 1) will hash differently in the AOT compiler and on the device.

Contributes to dotnet/runtime#82187 
Contributes to dotnet/runtime#78638
lambdageek added a commit that referenced this issue Mar 13, 2023
* [mono] Use `unsigned char` when computing UTF8 string hashes

The C standard does not specify whether `char` is signed or unsigned, it is implementation defined.

Apparently Android aarch64 makes a different choice than other platforms (at least macOS arm64 and Windows x64 give different results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime to optimize class name lookup.  As a result, classes whose names include UTF-8 continuation bytes (with the high bit = 1) will hash differently in the AOT compiler and on the device.

Fixes #82187
Fixes #78638

* [aot] add DEBUG_AOT_NAME_TABLE code for debugging the class names

   AOT compiler: Emits a second "class_name_table_debug" symbol that has all the class names and hashes as strings.

   AOT runtime: warns if a class is not found in the name cache

* Add regression test
lambdageek added a commit that referenced this issue Mar 14, 2023
The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes #82187
Fixes #78638
lambdageek added a commit to lambdageek/runtime that referenced this issue Mar 14, 2023
The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes dotnet#82187
Fixes dotnet#78638
lambdageek added a commit that referenced this issue Mar 30, 2023
…hes (#83303)

* [mono] Use `unsigned char` when computing UTF8 string hashes

The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes #82187
Fixes #78638

* Add regression test

---------

Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
lambdageek added a commit that referenced this issue Mar 30, 2023
…es (#83302)

* [mono] Use `unsigned char` when computing UTF8 string hashes

The C standard does not specify whether `char` is signed or unsigned,
it is implementation defined.

Apparently Android aarch64 makes a different choice than other
platforms (at least macOS arm64 and Windows x64 give different
results).

Mono uses `mono_metadata_str_hash` in the AOT compiler and AOT runtime
to optimize class name lookup.  As a result, classes whose names
include UTF-8 continuation bytes (with the high bit = 1) will hash
differently in the AOT compiler and on the device.

Fixes #82187
Fixes #78638

* Add regression test
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 30, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.