Cannot process file because of mark of the web error in Visual C# project

I have been working on an Outlook VSTO Plugin as part of a product that we are selling at As-tech. Often, when trying to build or publish the plugin, I...

I have been working on an Outlook VSTO Plugin as part of a product that we are selling at As-tech. Often, when trying to build or publish the plugin, I would encounter an error complaining that the project cannot be built because one of the resource files had the mark of the web (see below):

The error that is displayed when trying to build the project

It claims that I need to remove the Mark of the Web to process the file, but it soon became obvious when I encountered this error that this was not necessarily a simple process.

What is the Mark of the Web?

The Mark of the Web is a feature that was introduced by Microsoft to determine the origin of a file. If a file was downloaded from the Internet or from another location on a network, it would contain a comment in the file identifying the zone from which the file was downloaded from. Depending on this zone (e.g. intranet, internet etc) Windows would handle the file accordingly so as to avoid users from running or opening potentially harmful files from untrusted sources.

But why do I get this error?

The Mark of the Web is a great feature to have, but it's really unnecessary and confusing when we see it in Visual Studio while trying to build our project. But fear not, there are a few solutions to solve this error. Unfortunately there is no single solution that works every time so I've tried to list all the possible solutions I have found across the web as well as my own solutions to the problem with the hope that one of them works for you.

Solutions

I have listed the solutions from the most common and well-known solutions to the more obscure solutions. Hopefully one of the more common solutions work for you.

Solution 1: Unblock the file

The most common solution to this error is to simply Unblock the file. When you download a file from a network location, Windows marks it as blocked and you have to explicitly unblock it.

  1. Right-click the offending file and go to Properties.
  2. Click on the Unblock button or checkbox at the bottom of the dialog.
    unblock_checkbox-8471958a9f456c536c3b52306b81c41c-cab53
  3. Click OK to save your changes and see if it helps.

Tip: Unblock multiple files at once

If you have quite a few offending files, you can run a Powershell command in the directory with all the offending files to unblock all of them at once.

To do this, open Powershell and run the following command:

Get-ChildItem -Path '{PATH_TO_DIRECTORY_CONTAINING_OFFENDING_FILES}' -Recurse | Unblock-File

This should unblock all the files in the directory as well as in any sub-directories.

Solution 2: Make sure the file isn't being synchronised by any online storage service

If you are running OneDrive or Google Drive Sync on your computer, make sure the file is not being synchronised by any of these services. When these services upload and download files, the files can get the Mark of the Web preventing you from being able to build with them.

If this is the case, copy the files to a directory that is not being synchronised and then unblock all the files as shown in Solution 1.

Solution 3: Recreate the offending file

If a file has the Mark of the Web after being downloaded, you can create a new file with exactly the same name and then copy the contents of the downloaded file to the new file.

  1. Rename the file you downloaded and add something like _old to the end of the filename so you can create the new file.
  2. Create a new file by right-clicking in the folder and selecting New -> Text Document
  3. Rename the text document to the old filename (make sure you change the extension as well to the appropriate file extension)
  4. Open the old file and your newly-created file and copy the contents from the old file to the new file and save it.

This solution is a bit messy but it does work in some cases.

Solution 4: Delete the db.lock file in the solution folder

Another solution is to delete the db.lock file that exists in the .vs folder in your solution folder. This one's a bit of black magic, but it has reportedly fixed the issue for some people.

  1. Close Visual Studio IDE
  2. Make sure you can view hidden items in Windows Explorer
    hidden_items-d664eff0f336f86a2c799185dab840ed-52fd6
  3. Navigate to the solution folder and then open the .vs folder
  4. Navigate to {PROJECT/FILE NAME}/v15/Server/sqlite3
  5. Delete the db.lock file
  6. Open the solution again and try rebuild

Solution 5: Clean the project and rebuild it

Sometimes you need to clean the project before rebuilding it in order to resolve the error. Cleaning the solution removes any residual files that remain after previous builds. This gives you a clean slate to build the project on.

  1. Right-click on the project in Visual Studio
  2. Click on Clean
    clean_project-63626be270da7c7fd021d819129eba67-1848f
  3. Rebuild the solution once the clean is done.

Closing

Hopefully one of these solutions solved your problem. This problem really caused me a lot of headaches. If you find another solution to the issue, please leave the solution in the comments down below so as to help others.

Disclaimer

I cannot take responsibility of any damage or loss of files that occur while trying the above solutions. Please make backups of your files and be aware of the consequences of any actions you take.

References

Repost Notice

This article is reposted from my original article on the Astech website.