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
22.24k stars 1.76k forks source link

Failure to initialize App MainPage on startup after updating to RC1 #6063

Closed trueip9 closed 1 year ago

trueip9 commented 2 years ago

Description

After updating to RC1 my existing MAUI app project builds successfully but fails to initialize main page and terminates start up.

Troubleshooting steps attempted:

Still no luck

Steps to Reproduce

  1. Update Visual Studio from 17.2.0 Preview 2.1 to Preview 3.0
  2. Open existing solution with MAUI project (where MainPage = new NavigationPage(new MainPage); (Inherited from ContentPage)
  3. Update NuGet packages (Microsoft.Graphics.Win2D and Microsoft.WindowsAppSDK)
  4. Build and run for Windows (debug, any cpu)

Version with bug

Release Candidate 1 (current)

Last version that worked well

Preview 14

Affected platforms

Windows

Affected platform versions

net6.0-windows10.0.19041

Did you find any workaround?

Fresh default project builds and runs normally. Do not updete to RC1 if you already have project in development.

Relevant log output

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Exception has been thrown by the target of an invocation.
  Source=System.Private.CoreLib
  StackTrace:
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[TXaml](TXaml view, Type callingType)
   at TrueIP_Configurator.MainPage.InitializeComponent() in C:\Users\sniko\source\repos\TrueIP_Configurator\TrueIP_Configurator\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\MainPage.xaml.sg.cs:line 38
   at TrueIP_Configurator.MainPage..ctor() in C:\Users\sniko\source\repos\TrueIP_Configurator\TrueIP_Configurator\MainPage.xaml.cs:line 15
   at TrueIP_Configurator.App..ctor() in C:\Users\sniko\source\repos\TrueIP_Configurator\TrueIP_Configurator\App.xaml.cs:line 48
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   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.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument 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.GetOrAdd(TKey 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[T](IServiceProvider provider)
   at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args)
   at TrueIP_Configurator.WinUI.App.OnLaunched(LaunchActivatedEventArgs args) in C:\Users\sniko\source\repos\TrueIP_Configurator\TrueIP_Configurator\Platforms\Windows\App.xaml.cs:line 26
   at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args)
   at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
InvalidOperationException: .ctor is currently not enabled. To enable compatibility features you will need to call add `builder.UseMauiCompatibility()`.

MauiApp
    .CreateBuilder()
    .UseMauiApp<TApp>()
    .UseMauiCompatibility();
pekspro commented 2 years ago

I had the following lines in my .csproj:

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
    <OutputType>WinExe</OutputType>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

Removing this make my app start again without this exception. I also needed to update this SQLite reference to the latest preview:

<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.0-pre20220318192836" />

Maybe related: https://github.com/ericsink/SQLitePCL.raw/issues/465

Zetthard commented 2 years ago

Might be relevant: Three intances of "WMC100 Cannot resolve metadaata for WinUI types. Please ensure that Nuget Restore was sucessful." warnings started to appear in Error/Warning list console in VS after this update.

trueip9 commented 2 years ago

Workaround has been found: Remove xmlns:compat="clr-namespace:Microsoft.Maui.Controls.Compatibility;assembly=Microsoft.Maui.Controls" namespace and all controls using this namespace. It seems that issue has something to do with controls namespaces. edit: I'm using RelativeLayout, that's why I need Compatibility namespace. Or should I refactor to avoid using this layout? Looks like issue is in RelativeLayout ctor.

VincentBu commented 2 years ago

not repro with vs main build(32622.314)

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

jfversluis commented 1 year ago

It has been a while since this was reported. I'm going to be optimistic and assume this has been fixed in newer versions. If there is still something wrong, please feel free to open a new issue. Thanks!

ilsur-dev111 commented 1 year ago

@jfversluis Hi! In the latest version (currently version 7) the problem still exists when using RelativeLayout.

jfversluis commented 1 year ago

Thanks for confirming @ilsur-dev111 I've linked it to this one, I'm pretty sure that will be the same root cause: https://github.com/dotnet/maui/issues/12748

samhouts commented 1 year ago

https://github.com/dotnet/maui/issues/12748#issuecomment-1665874840