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

Dependency Injection: Attempted to access a missing method #9298

Closed
AstrNexus opened this issue Aug 9, 2022 · 4 comments
Closed

Dependency Injection: Attempted to access a missing method #9298

AstrNexus opened this issue Aug 9, 2022 · 4 comments
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup platform/windows 🪟 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Milestone

Comments

@AstrNexus
Copy link

Description

Page need need no parameter Constructor to work normally.

Steps to Reproduce

MauiProgram.cs

builder.Services.AddSingleton<MyService>();

AppShell.xaml

<Shell
    x:Class="MauiLab.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MauiLab"
    Shell.FlyoutBehavior="Disabled">
    <TabBar>
        <Tab Title="Hello">
            <ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
        </Tab>
        <Tab Title="World">
            <ShellContent ContentTemplate="{DataTemplate local:NewPage}" />
        </Tab>
    </TabBar>
</Shell>

MyService.cs

 public class MyService  {  }

NewPage.cs

public partial class NewPage : ContentPage
{
    public NewPage (MyService service) { InitializeComponent(); }
}

Launch App and switch to World Tab

UnhandledException in App.g.i.cs MauiLab.WinUI.App.InitializeComponent()
sender object {MauiLab.WinUI.App}

e {"Attempted to access a missing method."} | System.Exception {System.MissingMethodException}
"Cannot dynamically create an instance of type 'MauiLab.NewPage'. Reason: No parameterless constructor defined."

My debugger can't catch exception if app's first page's constructor need service injection.

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows 11 22622.436 with Visual Studio 17.3/17.4 Preview 1

Did you find any workaround?

Register page manually just like preview 13 announcing blog post
add builder.Services.AddTransient<NewPage>();

Relevant log output

No response

@AstrNexus AstrNexus added the t/bug Something isn't working label Aug 9, 2022
@jfversluis jfversluis added the area-core-hosting Extensions / Hosting / AppBuilder / Startup label Aug 11, 2022
@PureWeen
Copy link
Member

You need to register the pages as well unfortunately

Initially this wasn't a requirement but due to a bug with how ctor resolution works we had to make it so page registration was required.

@PureWeen PureWeen added this to the .NET 7 Planning milestone Aug 11, 2022
@PureWeen PureWeen modified the milestones: .NET 7 Planning, 7.0-rc2 Aug 30, 2022
@Redth Redth modified the milestones: 7.0-rc2, Backlog Aug 31, 2022
@ghost
Copy link

ghost commented Aug 31, 2022

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.

@Zhanglirong-Winnie Zhanglirong-Winnie added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Dec 12, 2023
@ghost
Copy link

ghost commented Dec 12, 2023

Hi @AstrNexus. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

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.

@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 1.1. Not repro this issue.

@ghost ghost closed this as completed Dec 19, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup platform/windows 🪟 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants