[Bug]: Application.Current is null on AppSettings.Start()
Jerome2606 opened this issue · comments
Jérôme Lambert commented
Steps To Reproduce
I have configured a fresh new Shiny Template project
Here are my PackageReference:
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="CommunityToolkit.Maui" Version="7.0.1" />
<PackageReference Include="CommunityToolkit.Maui.MediaElement" Version="3.0.1" />
<PackageReference Include="Prism.DryIoc.Maui" Version="9.0.271-pre" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.31" />
<PackageReference Include="Shiny.Framework" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.0" />
<PackageReference Include="Shiny.Extensions.Configuration" Version="$(ShinyVersion)" />
<PackageReference Include="Shiny.Logging.Sqlite" Version="$(ShinyVersion)" />
<PackageReference Include="Shiny.BluetoothLE" Version="$(ShinyVersion)" />
<PackageReference Include="Shiny.Jobs" Version="$(ShinyVersion)" />
<PackageReference Include="Shiny.Notifications" Version="$(ShinyVersion)" />
<PackageReference Include="Shiny.Net.Http" Version="$(ShinyVersion)" />
<PackageReference Include="Shiny.Push.AzureNotificationHubs" Version="$(ShinyVersion)" />
<PackageReference Include="ZXing.Net.Maui.Controls" Version="0.4.0" />
<PackageReference Include="Plugin.Maui.Audio" Version="2.1.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" />
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.6" />
<PackageReference Include="SkiaSharp.Extended.UI.Maui" Version="2.0.0-preview.86" />
Issue (ie.Compiler Error)
My Application.Current is null on line 12 of the Start() method in AppSettings.cs file :
public void Start()
{
Application.Current!.UserAppTheme = this.CurrentTheme;
this.WhenAnyValue(x => x.CurrentTheme)
.Skip(1)
.Subscribe(x => this.CurrentTheme = x);
}
I have this error on local debugging on a Windows machine and target an Android emulator (Pixel 5 - API 33)
My RegirsterInfrastructure:
static MauiAppBuilder RegisterInfrastructure(this MauiAppBuilder builder)
{
builder.Configuration.AddJsonPlatformBundle();
builder.Logging.AddSqlite(Path.Combine(FileSystem.AppDataDirectory, "logging.db"));
#if !MACCATALYST
builder.Logging.AddAppCenter(builder.Configuration["AppCenterKey"]);
#endif
#if DEBUG
builder.Logging.SetMinimumLevel(LogLevel.Trace);
builder.Logging.AddDebug();
#endif
var s = builder.Services;
s.AddSingleton(AudioManager.Current);
s.AddShinyService<AppStartup>();
s.AddShinyService<AppSettings>();
s.AddSingleton<Shiny.Example.Services.MySqliteConnection>();
s.AddJob(typeof(Shiny.Example.Delegates.MyJob));
s.AddBluetoothLE();
s.AddHttpTransfers<Shiny.Example.Delegates.MyHttpTransferDelegate>();
#if ANDROID
// if you want http transfers to also show up as progress notifications, include this
s.AddShinyService<Shiny.Net.Http.PerTransferNotificationStrategy>();
#endif
s.AddNotifications<Shiny.Example.Delegates.MyLocalNotificationDelegate>();
// TODO: Please make sure to add your proper connection string and hub name to appsettings.json or this will error on startup
s.AddPushAzureNotificationHubs<Shiny.Example.Delegates.MyPushDelegate>(
builder.Configuration["AzureNotificationHubs:ListenerConnectionString"],
builder.Configuration["AzureNotificationHubs:HubName"]
);
s.AddDataAnnotationValidation();
return builder;
}
Allan Ritchie commented
Thanks for the report. This is fixed for the next release.
Jérôme Lambert commented
Thank you for the quick support.
I confirm that the fix applied on my side is fixing the issue :)