I know this question is on this site. But all answers are associated with some program statement.
In my case no.
I updated Visual Studio to Microsoft Visual Studio Community 2022 (64-bit) version 17.8.3, and after that I can’t build a very simple (i.e. template) console project. The ClassLibrary project is building normally.
My code in Program.cs:
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
That’s all.
My error:
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: Unexpected error while executing task "CreateAppHost".
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018:
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в System.IO.MemoryMappedFiles.MemoryMappedFile.CreateCore(SafeFileHandle fileHandle, String mapName, HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity)
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile(FileStream fileStream, String mapName, Int64 capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, Boolean leaveOpen)
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.NET.HostModel.ResourceUpdater.Update()
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>b__1()
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func)
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMacOSCodeSign)
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore()
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.NET.Build.Tasks.TaskBase.Execute()
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:Program Filesdotnetsdk8.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(709,5): error MSB4018: в Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
1>Building the project "RenamedConsole.csproj" completed with an error.
Any ideas about?
I tried the Debug/Release configuration, searched for answers on this forum – to no avail.
But I found a very important fact:
The “Startup project” item in the solution properties is not checked.
After checking this point and rebuilding the project, this error still occurred.
AND!
This item is again unchecked.
2
Answers
The answer has been found. The console application was located on a virtual Google Drive. After transferring to a standard disk, the error disappeared.
The issue looks like related to the lock of the dll file.
You could check which process lock the dll file, or you and try to restart your computer and try again.