-
Notifications
You must be signed in to change notification settings - Fork 119
Description
Environment:
- OS: Windows 11, 10.0.26100 Build 26100
- Framework: net8.0
- Type of application: Console Application
- Version of AspectInjector: >=2.9.0
Describe the bug
Starting from Version 2.9.0 (switch to MSBuild Task for Aspect Injection), the MS-build breaks (Run from Visual Studio 2022, 2026, and also from terminal directly using dotnet build. When running a build it always fails with the following error message:
C:\Program Files\dotnet\sdk\10.0.100-rc.1.25451.107\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(850,5): error MSB4018:
The "CreateAppHost" task failed unexpectedly.
System.IO.IOException: The process cannot access the file '[...]\obj\Debug\net8.0\Application.dll' because it is being used by another process.
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at Microsoft.NET.HostModel.ResourceUpdater.AddResourcesFromPEImage(String peFile)
at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass8_0.b__1()
at Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func)
at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMac
OSCodeSign, Boolean disableCetCompat, DotNetSearchOptions dotNetSearchOptions)
at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
Note: This error was copied from a build which used the MSBuild from VS 2026, with the preview version of .Net 10. However, the issue is the same when using VS 2022 Preview with latest MSBuild matching .Net 8.
I tried running the build (after cleaning bin and obj folders, stopping build servers, killing all MSBuild, devenv, and .Net host tasks) with dotnet build -nodeReuse:false, which gives a different but still faulty behaviour:
First build fails with the message:
The "CreateAppHost" task failed unexpectedly.
System.AggregateException: One or more errors occurred. (Access to the path '[...]\obj\Debug\net8.0\apphost.exe' is denied.) (Access to the path '[...]\obj\Debug\net8.0\apphost.exe' is denied.)
---> System.UnauthorizedAccessException: Access to the path '[...]\obj\Debug\net8.0\apphost.exe' is denied.
at System.IO.FileSystem.DeleteFile(String fullPath)
at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass8_0.b__1()
at Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func)
at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMac
OSCodeSign, Boolean disableCetCompat, DotNetSearchOptions dotNetSearchOptions)
--- End of inner exception stack trace ---
at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMac
OSCodeSign, Boolean disableCetCompat, DotNetSearchOptions dotNetSearchOptions)
at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
---> (Inner Exception #1) System.UnauthorizedAccessException: Access to the path '[...]\obj\Debug\net8.0\apphost.exe' is denied.
at System.IO.File.Delete(String path)
at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMac
OSCodeSign, Boolean disableCetCompat, DotNetSearchOptions dotNetSearchOptions)<---
And Second build is then successful.
To Reproduce
Creating a new Console Application which targets .net 8 and simply prints "Hello World" already fails building if the reference for AspectInjector 2.9.0 is added. 2.8.2 works fine.
Additional context
I also tried 2.9.0-pre4, same behaviour.