An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Thank you for reaching out.
This happens because the project is accidentally targeting a Windows SDK version that ends with “.1” (for example 10.0.19041.1). In .NET 10, those “.1” Windows target versions route the build to a CsWinRT 3.x (preview / not ready) path. When that preview path isn’t available (or the targeting pack can’t be resolved), the build task ends up with an empty WinRT runtime reference path. Then MSBuild tries to compute a folder using GetDirectoryName(''), and .NET throws “The path is not of a legal form” because an empty string is not a valid path. That’s why you see MSB4184 pointing into Microsoft.NET.Windows.targets under C:\Program Files\dotnet\sdk\...\ (it’s the SDK targets file reporting the failure, not your code).
The “Permission denied / Save file as under C:\Program Files\dotnet…” pop‑up is a side effect of the same situation: C:\Program Files\dotnet\... is a protected install location, and builds should not need to write there. So the right fix is not editing anything under the SDK folder, but correcting the project’s Windows target so the build resolves WinRT/CsWinRT paths normally.
Steps
- In Project Properties (or in the project settings UI), change the Windows SDK / Target OS version from a value ending in
.1to the matching value ending in.0.- Example: change
10.0.19041.1→10.0.19041.0 - If you set the target in the project file, make sure the TargetFramework Windows version also ends in
.0(not.1). - After switching to a “.0” Windows target version, rebuild. The WinRT path resolves again, so
GetDirectoryName(...)no longer receives an empty string and the build succeeds.
- Example: change
References
- Visual Studio Developer Community: Microsoft’s resolution states to use
10.0.19041.0and that the “.1” versions are for CsWinRT 3 (not ready), which leads to this failure: https://developercommunity.visualstudio.com/t/New.net10consolewithwindowsruntime/11002839 - Microsoft Learn (MSBuild): MSB4184 is thrown when MSBuild can’t evaluate an expression (like
GetDirectoryName('')):
https://learn.microsoft.com/en-us/visualstudio/msbuild/errors/msb4184?view=visualstudio
Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer". So that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.