Skip to content

UnauthorizedAccessExceptions are getting raised when building a blank MAUI app when using .NET 9.0 #9133

Open

Description

Description

I just moved to MAUI 9 this morning (specifically 9.0.0-preview.6.24327.7). I was using .NET 8.0 prior to this and everything was fine. I noticed that the first build of solution would work fine, but if I did a rebuild all, the build would fail with an UnauthorizedAccessException. The only way I can get it to go away is to close and reopen VS (I'm using 17.11.0 Preview 3.0, for the record, running in admin mode on Win 10). After that, it builds again, but only once before I start getting the UnauthorizedAccessExceptions.

To investigate, I made a blank .NET MAUI 8 app and tried it - everything builds fine. You can 'Rebuild All' as many times as you want and it'll compete successfully.

Then I made a blank .NET MAUI 9 app and built it - it was fine the first time. Then I tried 'Rebuild All' and, unfortunately, ran into the same UnauthorizedAccessExceptions during the build:

Error (active)	XARDF7019	System.UnauthorizedAccessException: Access to the path 'GoogleGson.dll' is denied.
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
   at Xamarin.Android.Tasks.RemoveDirFixed.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs:line 54	MauiApp2 (net9.0-android)	C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.99.0-preview.6.340\tools\Xamarin.Android.Common.targets	2503

and

Error (active)	XALNS7019	System.UnauthorizedAccessException: Access to the path 'D:\Projects\MauiApp2\obj\Debug\net9.0-android\android\assets\armeabi-v7a\MauiApp2.dll' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalDelete(String path, Boolean checkHost)
   at Microsoft.Android.Build.Tasks.Files.CopyIfChanged(String source, String destination) in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/Files.cs:line 125
   at Xamarin.Android.Tasks.MonoAndroidHelper.CopyAssemblyAndSymbols(String source, String destination) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs:line 344
   at Xamarin.Android.Tasks.LinkAssembliesNoShrink.CopyIfChanged(ITaskItem source, ITaskItem destination) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs:line 161
   at Xamarin.Android.Tasks.LinkAssembliesNoShrink.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs:line 76
   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25	MauiApp2 (net9.0-android)	C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.99.0-preview.6.340\tools\Xamarin.Android.Common.targets	1407

These all seem to be Android-releated. And when I try to deploy the successful build to my Android device, I get this error:

Error		XA0127: Error deploying 'files/.__override__/arm64-v8a/ar//Microsoft.Maui.Controls.resources.dll' using 'xamarin.sync: error: could not open 'files/.__override__/arm64-v8a/ar//Microsoft.Maui.Controls.resources.dll'.'.
Please set the 'EmbedAssembliesIntoApk' MSBuild property to 'true' to disable Fast Deployment in the Visual Studio project property pages, or edit the project file in a text editor.

I never got this error with .NET 8.0. Again, this is a fresh MAUI 9.0 app.

Steps to Reproduce

  1. Create a new, default .NET MAUI 9.0 app (use 9.0.0-preview.6.24327.7).
  2. Rebuild it. It should succeed.
  3. Rebuild it again. It should fail with an UnauthorizedAccessException.

Link to public reproduction project repository

https://github.com/whodges/mauiapp1

Version with bug

9.0.0-preview.1.9973

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.70

Affected platforms

Android

Affected platform versions

Android 31

Did you find any workaround?

Close and restart Visual Studio (but you'll only get one build out of it).

Relevant log output

binlog_success.zip
binlog_fail.zip
binlog_deploy_fail.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions