Share via

Issue to the bug

Jonathan 270 Reputation points
2026-06-23T08:41:10.86+00:00

Hi,

Can you help to the bug below? Which event is causing the issue?

User's image

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

Nancy Vo (WICLOUD CORPORATION) 6,510 Reputation points Microsoft External Staff Moderator
2026-06-23T09:21:10.6266667+00:00

Hello @Jonathan ,

Thanks for your question.

In your screenshot, the code is doing some PDF paperwork. However, when it is done with the PDF task, it never actually builds or returns the application. The method just ends.

The compiler is throwing the CS0161 error because the factory broke its contract—the operating system is waiting for an app, but the method didn't return one.

I recommend returning statement at the very end. You can refer to following code example:

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();

        builder.UseMauiApp<App>();

        // Drop your PDF testing script here for now
        // string inputFilePath = @"C:\path\to\your\input.pdf";
        // ... rest of the try/catch logic ...

        return builder.Build();
    }

    // Keep the PDF helper method outside the main builder
    // public static void InjectTextIntoPdf(...)
}

I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.

Was this answer helpful?

2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-06-23T08:41:30+00:00

    The error is raised by the CreateMauiApp() method itself.

    CreateMauiApp() is declared with a return type (most likely MauiApp), but in the code shown there is no return statement. That’s why the compiler reports:

    MauiProgram.CreateMauiApp(): not all code paths return a value

    To fix it, ensure that every execution path in CreateMauiApp() ends with a return of the appropriate object, for example:

    public static MauiApp CreateMauiApp()
    {
        // your setup code
    
        return builder.Build();   // or whatever object CreateMauiApp is supposed to return
    }
    

    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.