dansiegel / Mobile.BuildTools

The Mobile.BuildTools makes it easier to develop code bases in a clean, consistent, secure, and configurable way. Determine at Build which environment your app needs to run on, and what Client Secrets it should have. Plus many more amazing features!
http://mobilebuildtools.com
MIT License
228 stars 29 forks source link

System.UnauthorizedAccessException when trying to start a Maui WinUI app with Mobile.BuildTools.Configuration #320

Open BurkusCat opened 1 year ago

BurkusCat commented 1 year ago

Description

Android + iOS Maui Mobile.BuildTools.Configuration seems to work fine! Trying to initialise the configuration manager/register the dependency causes an exception for WinUI.

Full error message: System.UnauthorizedAccessException: 'Access to the path 'C:\WINDOWS\system32\Configuration' is denied.'

Reproduction Steps

Steps to reproduce the behavior:

  1. Add Mobile.BuildTools and Mobile.BuildTools.Configuration to a Maui project
  2. Add your app.config files as raw MauiAssets
  3. Register the ConfigurationManager instance with DI
  4. In the platform specific Window's App.xaml.cs, call ConfigurationManager.Init(true);

Expected Behavior

The WinUI app launches and the groundwork for using Mobile.BuildTools is setup

Actual Behavior

The app crashes on startup with an exception: image

Removing the config code and only registering the ConfigurationManager.Current dependency: image

When I try debugging inside the library, it appears to be using the CommonConfigManager which I think is the .NET Standard code path (intended for console apps/servers?). image

One theory I have is that the library doesn't know about WinUI TargetFramework (https://github.com/dansiegel/Mobile.BuildTools/blob/master/src/Mobile.BuildTools.Configuration/Mobile.BuildTools.Configuration.csproj#L42) and is therefore not invoking any of the UWP code (would the UWP code work for WinUI?).

Environment

Reproduction App

https://github.com/BurkusCat/MbtConfigurationWinUIException

dansiegel commented 1 year ago

Well for starters WinUI isn't a supported or tested target. If you'd like to contribute to the project I'd be happy to have it support WinUI. But I can't promise timelines if you're waiting on me.