dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

Using System.Drawing.Primitives.Color App Crashes after splash Screen on Android Release Mode #17131

Open ozersenol opened 1 year ago

ozersenol commented 1 year ago

Description

Hello, My app crushes after splash screen on release mode. It works perfectly on debug mode.

Error given on device log is:

08-31 12:38:37.985 EVEREST-EVERPAD DC-1032 Error 29367 AndroidRuntime android.runtime.JavaProxyThrowable: System.InvalidProgramException: Invalid IL code in ProxiWash.KasaApp.App:InitializeComponent (): IL_0002: stloc.0

and

08-31 12:22:08.921  EVEREST-EVERPAD DC-1032 Error   28503   AndroidRuntime  
   at ProxiWash.KasaApp.App..ctor()
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   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 callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   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 callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2[[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func`2[[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 key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IApplication](IServiceProvider provider)
   at Microsoft.Maui.MauiApplication.OnCreate()
   at Android.App.Application.n_OnCreate(IntPtr jnienv, IntPtr native__this)
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
    at crc6488302ad6e9e4df1a.MauiApplication.n_onCreate(Native Method)
    at crc6488302ad6e9e4df1a.MauiApplication.onCreate(MauiApplication.java:28)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1189)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6488)
    at android.app.ActivityThread.access$1400(ActivityThread.java:226)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1884)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7386)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)

is this a bug or something missing from my side? If any can help me I really appriciate.

I tried all possible combinations on release with settings: AOT/non-AOT, Linked or Non-linked etc.

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

7.0.92

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 10

Did you find any workaround?

No response

Relevant log output

No response

Eilon commented 1 year ago

@jonathanpeppers - ideas on this? It feels like an AOT type of thing to me, but the report says it fails even without AOT.

jonathanpeppers commented 1 year ago

System.InvalidProgramException: Invalid IL code in ProxiWash.KasaApp.App:InitializeComponent (): IL_0002: stloc.0

This sounds like it could be a XamlC issue, because it uses Mono.Cecil to write IL inside the InitializeComponent() method.

@ozersenol does the problem go away if you skip XamlC on this type, ProxiWash.KasaApp.App:

[XamlCompilation(XamlCompilationOptions.Skip)]
public class App
{
//...
}

If it does, maybe you can share the offending .xaml file or a code snippet to reproduce this? Thanks.

ghost commented 1 year ago

Hi @ozersenol. 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.

ozersenol commented 1 year ago

System.InvalidProgramException: Invalid IL code in ProxiWash.KasaApp.App:InitializeComponent (): IL_0002: stloc.0

This sounds like it could be a XamlC issue, because it uses Mono.Cecil to write IL inside the InitializeComponent() method.

@ozersenol does the problem go away if you skip XamlC on this type, ProxiWash.KasaApp.App:

[XamlCompilation(XamlCompilationOptions.Skip)]
public class App
{
//...
}

If it does, maybe you can share the offending .xaml file or a code snippet to reproduce this? Thanks.

Thank you @jonathanpeppers It worked with [XamlCompilation(XamlCompilationOptions.Skip)] and saved my day !

and code is very ordinary and I did not add anything more since all design comes from blazor part.

 [XamlCompilation(XamlCompilationOptions.Skip)]
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new MainPage();
        }
    }

<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ProxiWash.KasaApp"
             xmlns:drawing="clr-namespace:System.Drawing;assembly=System.Drawing.Primitives"
             x:Class="ProxiWash.KasaApp.App">
    <Application.Resources>
        <ResourceDictionary>

            <drawing:Color x:Key="PageBackgroundColor">#512bdf</drawing:Color>
            <drawing:Color x:Key="PrimaryTextColor">White</drawing:Color>

            <Style TargetType="Label">
                <Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
                <Setter Property="FontFamily" Value="OpenSansRegular" />
            </Style>

            <Style TargetType="Button">
                <Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
                <Setter Property="FontFamily" Value="OpenSansRegular" />
                <Setter Property="BackgroundColor" Value="#2b0b98" />
                <Setter Property="Padding" Value="14,10" />
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>
jonathanpeppers commented 1 year ago

@ozersenol this part seems suspicious:

xmlns:drawing="clr-namespace:System.Drawing;assembly=System.Drawing.Primitives"

Can you just use <Color/>? This would use Microsoft.Maui.Graphics.Color, I believe.

ozersenol commented 1 year ago

Absolutely you are right. I changed to and rolled back without XamlC, it worked ! I guess it was and old temple that use Drawing.Color that I have not noticed. New project templates use only color... Thank you!

jonathanpeppers commented 1 year ago

Ok great, so I think we can leave this open, as you should get a build error instead of a runtime error for this, if possible.

But we can move to the backlog for now, thanks!

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.