Issue with android application context in .net 8

James Brooksbank 20 Reputation points

Hi, so i am working on modifying an existing maui app which is working fine in .net7, however there is a problem with the version in .net8.

After examining both instances i have determined that there is a difference between the 2 versions, which is the only difference.

In both versions i am using the code line at the bottom.

In .net7, when i examine con, i can drill down into the base and see that it is "Microsoft.Maui.MauiApplication}"

I can examine all the other properties within that without issue.


However, in .net8, with the same line, you can see the base, but underneath that, all you see is the message "object reference not set to an instance of an object "

Everything else is the same, however there is something wrong in the initialisation of the MauiApplication which i believe is causing this due to .net8.

Can someone help me resolving this issue.


var con = Android.App.Application.Context
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,207 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 71,936 Reputation points Microsoft Vendor


    I tried to use following code, I can get the same issue.

    #if ANDROID
                var res1 = Microsoft.Maui.MauiApplication.Context;
                var context = Platform.AppContext;           
                var reS2=   Android.App.Application.Context;

    Q&A is not a bug reporting or tracking system. Please report it in the Maui github repository at . We will clear details to be able to reproduce and troubleshoot the problem. When you post it, please include version numbers, exact repro steps, and the difference between the expected behaviour and actual behaviour.

    By the way, if you want to get current Activity, you can use var CurrentActivity= Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;, it is working as normal in .NET 8

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful