MSB4018 horror (not a simple error)

Guglielmo Cancelli 5 Reputation points

I would like to report that for a few days now, even when creating a new empty VB solution with only the default form, when I try to compile I always get MSB4018, which obviously doesn't make any sense, being the default project.

I tried repairing the VS2022 installation but that did not change the result. Not even running InstallCleanup and then performing a clean re-installation changed anything.

A few days earlier I had done an update of VS.

In short, I can no longer code! 🤬

I'm using win10

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,096 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Guglielmo Cancelli 5 Reputation points

    This is the integral error I receive.

    However, I noticed that if I create a new project on disk C the error does not occur. I get this error from projects created on the Google synchronized folder. But only in this last week, it was working before.

    I have no alternative to using Drive, so how can I solve it?

    Errore MSB4018 errore imprevisto dell'attività "CreateAppHost". System.IO.IOException: Impossibile eseguire l'operazione specificata su un file la cui sezione mappata dall'utente è aperta. in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) in System.IO.MemoryMappedFiles.MemoryMappedFile.CreateCore(SafeFileHandle fileHandle, String mapName, HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity) in System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile(FileStream fileStream, String mapName, Int64 capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, Boolean leaveOpen) in Microsoft.NET.HostModel.ResourceUpdater.Update() in Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>b__1() in Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func) in Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResourcesFrom, Boolean enableMacOSCodeSign) in Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in Microsoft.NET.Build.Tasks.TaskBase.Execute() in Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() test C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets 709

    1 person found this answer helpful.

  2. Tianyu Sun-MSFT 22,261 Reputation points Microsoft Vendor

    Hello @Guglielmo Cancelli ,

    Welcome to Microsoft Q&A forum.

    Please try following to clean some cache files and fix any corrupted files first.

    1. Run CMD as administrator, run DISM.exe /Online /Cleanup-image /Restorehealth command, wait for it finishes running, run sfc /scannow command.
    2. Navigate to C:\Users\{username}\AppData\Local\Microsoft\VisualStudio\17.0_XXXXXXXX folder, rename this folder.
    3. Reboot your machine and rename %Temp% folder(C:\Users\{username}\AppData\Local\Temp).
    4. Update Windows OS and make sure that there’s no Windows Update Errors.
    5. Launch VS as administrator, create a new project and check again.

    Besides, do you have full permissions on your machine(please check following: antivirus, group policy, permission limitations)? Does running VS as administrator work?

    If there are more detailed error messages, please share them with us to check further.

    Best Regards,


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.