dansiegel / dansiegel/Mobile.BuildTools

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

Open
#320 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
224
Forks
28
PR merge metrics
No merged PRs in 30d

Description

# 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](https://user-images.githubusercontent.com/7528322/210813773-4ff33080-ca0e-4d7c-b305-720f48aa5c63.png)

Removing the config code and only registering the ConfigurationManager.Current dependency:
![image](https://user-images.githubusercontent.com/7528322/210816551-95bf50c7-aeef-4a3d-936f-56dc61677faf.png)

When I try debugging inside the library, it appears to be using the `CommonConfigManager` which I think is the [.NET Standard](https://github.com/dansiegel/Mobile.BuildTools/blob/master/src/Mobile.BuildTools.Configuration/Platform/NetStandard/CommonConfigManager.netstandard.cs) code path (intended for console apps/servers?).
![image](https://user-images.githubusercontent.com/7528322/210814185-4ec519d5-de2c-4dc2-84ca-ad8556a16341.png)

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

- OS: Windows 11
- IDE: VS2022
- BuildTools Version: 2.0.245
- IDE Version: 17.4.0
- Build Target Framework: net6.0-windows10.0.19041.0

## Reproduction App
https://github.com/BurkusCat/MbtConfigurationWinUIException

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.