-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnauthorizedAccessExceptions are getting raised when building a blank MAUI app when using .NET 9.0 #9133
Comments
Hi I'm an AI powered bot that finds similar issues based off the issue title. Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you! Open similar issues:
Closed similar issues:
|
I dug in a bit more, trying different versions. Everything builds fine with 8.0.70, and then this rebuild issue appears with 9.0.0-preview.1.9973. |
Can you create and attach a binlog please? |
Yep, np. I editted in two attached two binlogs: binlog_success is from the first rebuild, and binlog_fail is from the subsequent rebuilds. EDIT: Added a third one, which is when I try and deploy the second build. It's the same UnauthorizedAccessException error, but involving different files. |
This issue has been verified using Visual Studio 17.11.0 Preview 3 (9.0.0-preview.1.9973 & 9.0.0-preview.6.24327.7). Cannot repro it. |
Ok - I just tried it on a completely different computer that I installed the latest .NET 9 SDK on, along with the latest preview version of VS 2022 (9.0.0-preview.6.24327.7 and 17.11.0 Preview 3.0, respectively), and I got the exact same UnauthorizedAccessException involving 'GoogleGson.dll'. I just made a github of the .NET 9.0 MAUI app itself, but again, it's just the default app that VS creates for you: https://github.com/whodges/mauiapp1.git. Not sure if that helps. I'm 100% open to doing anything that would shed more light on this for you all. I was going to chalk this up to something involving my environment, but reproducing it on a separate machine concerns me. I totally get though that this is something that would've been noticed early on your end, so why I seem to be the only one experiencing it is definitely odd. EDIT: Here's the binlog from the other machine: EDIT2: A screenshot just because: EDIT3: And again, if I switch to .NET 8 (MAUI 8.0.70), everything is fine. |
Just tried again with 17.11.0 Preview 4.0. Same issue: the first build works, then 'Rebuild Solution' results in Note that this only happens with Debug builds. Everything is fine with Release. |
I get the same error in a MAUI Project with .NET9 and with Visual Studio 17.11 Preview 2.1. With NET8 everything works without problems |
The last error:
Should be fixed in: Which should hopefully be in .NET 9 Preview 7. |
I tried with the .NET 9 Preview 7 build we are working on, I can't seem to reproduce the If you are having this issue, can you use a tool like ProcessExplorer to find out what process is locking the file:
|
I tried both procexp and tasklist; unfortunately neither reports that any program currently has the file in use. I dug in a bit more though and found that every file in EDIT: I tried this using 17.11.0 Preview 7.0. |
Do you have any third party Visual Studio extensions installed (just trying to eliminate causes) for things like code formatting or intellisense. Those files are clearly being locked by VS but its odd that it does not show up in the procexp 🤔 |
The only non-MS extensions I have are Multiline Search and Replace (Helixsoft) and Xamarin.Android SDK. AV is just MS Defender. But on the other Win 10 system I tried this on, there's no AV and no extensions installed. Yes I have Hot Reload active on both, but just tried disabling it to no avail; the same error occurs. |
I tested this on a DevBox/Virtual Machine, and I noticed the project by default is saved on a Dev Drive. Let me just check if anything different happens on a regular drive where Windows Defender will do its standard scanning on file writes. @whodges does anything different happen if you have a Windows Defender exclusion for the folder where the project is saved? |
Just tried the exclusion; no luck |
Still occurs on version 17.12.0 Preview 1.0 |
I've got similar issue. 17.12.0 Preview 1.0/.NET9 Preview 7 -> New MAUI project -> Build: Output: It works when I start VS as Administrator. But after a few builds and run it appears again. |
Interesting - it happens for me running VS as admin no matter what after the first build. I also wonder if it could be some regional settings for whatever weird reason? I’m in Canada. |
This will help diagnose these types of issues: But it looks like I should add |
…zedAccessException Context: dotnet/android#9133 In the above issue, a customer got: error 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 Let's expand upon 11fad9d to include `UnauthorizedAccessException`. Unfortunately, I wasn't able to *reproduce* this exception, I tried several things: * `File.Delete` on a file * `File.Delete` on the currently running test assembly * `File.SetAttributes` to `ReadOnly` on a file * `Directory.Delete` on a directory with readonly files I settled on just throwing `UnauthorizedAccessException` with the exact same message reported in dotnet/android#9133. It may or may not work, depending on if the message has a valid path to the file. This still seems useful though -- better than nothing.
Hi! Case 1:
Case 2:
Case 3:
Important Note: I’ve tried the mentioned scenarios with a blank/sample app using .NET 8.0 LTS, and it works perfectly. Additionally, deployment to the emulator also seems faster. TargetFrameworks: net9.0-android;net9.0-ios;net9.0-maccatalyst Exception: System.UnauthorizedAccessException: Access to the path '<MY PATH :)>\repos\MauiApp2\MauiApp2\obj\Debug\net9.0-android\android\assets\armeabi-v7a\MauiApp2.dll' is denied. |
Fixes: #9133 Context: https://discord.com/channels/732297728826277939/732297916680765551/1308554103206580244 Context: 86260ed Various customers have been reporting `UnauthorizedAccessExceptions` in incremental builds, which seems to be a new problem in .NET 9. We were not able to reproduce the issue locally, but with the number of reports it seems to be a real issue. One customer shared a [`MSBuild.dmp`][0] file (while the file was locked), where I could observe the objects in memory: MemoryMappedViewStream 132 Mono.Cecil.PE.Image 100 Mono.Cecil.ModuleDefinition 100 Mono.Cecil.TypeDefinition 100 Mono.Cecil.TypeDefinition[] 100 List<Mono.Cecil.TypeDefinition> 1 Xamarin.Android.Tasks.NativeCodeGenState [Static variable Xamarin.Android.Tasks.NativeCodeGenState.<Template>k__BackingField] 1 Then realized the problem was: * We opened some `.dll` files with `Mono.Cecil`. * They were never closed. * Future incremental build attempts would fail on various operations of the same `.dll` files. We were also storing some static state (`NativeCodeGenState`) to be shared across multiple MSBuild tasks: partial class NativeCodeGenState { public static NativeCodeGenState? Template { get; set; } } `NativeCodeGenState` also holds a `XAAssemblyResolver` in a `Resolver` property. This means this `XAAssemblyResolver` instance would *also* be kept alive. It appears we only use the static `Template` property for a `bool` flag, so I changed the property to a `bool` instead: partial class NativeCodeGenState { public static bool TemplateJniAddNativeMethodRegistrationAttributePresent { get; set; } } After this change, we can safely dispose `Resolver` instances. I looped over the `NativeCodeGenState` instances disposing of each `Resolver` at the end of the `<GenerateJavaStubs/>` and `<GeneratePackageManagerJava/>` MSBuild tasks. [0]: https://drive.google.com/file/d/12dOkO6ZdbK67sNeY_PVS4d0mgnLyOwUA/view?pli=1
* Initial commit with readme * Added alternative implementation to demonstrate the advantage of DI. * Added Union Architecture & Unit Tests (#1) * Setup Unit Tests and create separate physical libraries to make it more testable. * WIP - testing * Union + Unit Testing Finish * Example of MVVM binding to a Map Control * Example of MVVM binding to a Map Control * Removed secret * Removed secret * Removed secret * Bump back to version 8 because of dotnet/android/issues/9133
i got the same issue with .net9 System.UnauthorizedAccessException: Access to the path 'CommunityToolkit.Maui.Core.dll' is denied. |
@amryakout2024 Yes...it is still an issue...but I think it has been fixed...we need to wait for the patch release to .NET 9 I think...not sure when that will be though |
@amryakout2024 you can kill the blocking process, it will definitely be faster than rebuilding whole project |
I am also having the same issue. So annoying that I have to restart VS every time to have a successful build. Version 17.12.2 |
You don't. Run |
I am dev-tunneling an Api locally on the same machine, so running this would also kill the msbuild for the api as well. We need an actual fix not a work around. |
The issue is already fixed and all we are waiting for is the next release. As for other workaround did you try just killing the process that is blocking the file instead of killing all |
Good to hear that it's been fixed. I tried killing the msbuild for the MAUI, it works sometimes, but most of the times it doesn't work. I didn't kill all of msbuild as the other one is for the API powering the application. |
Great, glad to hear that! 👍 |
I just updated to visual studio 17.12.3 which was released today and the problem still happens. running |
Yes, the problem is still not solved - I am seeing the same thing with 17.12.3 |
There were a couple of fixes in this area. The commit be53aed might well have been related. And GitHub Auto closed this Issue when that PR was merged. That said is it more accurate that PR #9531 fixes this issue. This has been cherry-picked to the .net 9 release branch via 974a5ab. I'm not sure when that is being released though. @jonpryor any ideas when that commit will actually make it into a release? If anyone is seeing this on the 17.12.3 please get us binlogs of the issue (with the error in it) as it will give us some pointers as to what is going on . |
It looks like the "fix" was released in .NET Android SDK 35.0.24. |
I ran the 17.12.3 update on a VM and I can confirm that the .NET Android 35.0.24 update is not present. I also ran |
The fix is inserted in the next VS 17.13 Preview, but we will also ship it to NuGet.org. |
Are binlogs from the error on 17.12.3 still of interest then? I could provide if yes. |
Yes, please. When can we expect the next update? This problem is really annoying and a blocker for a normal workflow. |
There are no Android changes in this release, so I wouldn't expect anything to change. |
This released today: So, you can install either VS 17.13 Preview 2, or run |
Can't reproduce the issue on 35.0.24 anymore! |
Just tried it and it works for me! Thanks! |
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:
and
These all seem to be Android-releated. And when I try to deploy the successful build to my Android device, I get this error:
I never got this error with .NET 8.0. Again, this is a fresh MAUI 9.0 app.
Steps to Reproduce
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
The text was updated successfully, but these errors were encountered: