Tuesday, 6 October 2009

Visual Studio: Unknown Build Error (HRESULT 0x80131515)

If you are receiving this really informative error message in Visual Studio and looking for a solution, I hope the following can help you. I spent wasted a fair bit of time trying to figure this out. Funny thing is, it’s actually quite common in the post-XP(i.e. Vista and Windows 7) era (I’ve had it myself several times now)..

The Cause

After much digging, it turns out the issue is caused by the file blocking placed on downloaded assemblies. For example, I had the following after downloading the binaries for Autofac and adding it to my project:

Error    1    Unknown build error, 'Could not load file or assembly 'file:///c:\{Project}\lib\Autofac.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)'     {Project}

To Fix

image The good news, is this is pretty easy to fix (as are most problems when you know the cause!).

Open up the file properties dialog (right click in Explorer > Properties) and then you will see the security warning:

This file came from another computer and might be blocked to help protect the computer

That’s what we are after – click the “Unblock” button. Click “OK” (or “Apply” > “OK” if it makes you feel better). Flick back to VS and fire up another build and all should be right in your world and you can go back to cutting code (you don’t need to close/reopen project etc).

WTF’s/Questions to Note

  • Considering how many assemblies we devs download from the Internet, how has this not been more common?
  • What is with the language in the file properties? “The file might be blocked?” – If Windows doesn’t know, who does?!
  • What operation is VS trying to perform that is “not supported” – one would assume that an IO error of some kind is occurring – why it not at least saying “error reading file” to at least point us to the file?

Hope this helps people and saves them some time!

12 comments:

IanR said...

Thanks Rob - I wasted an hour on this before finding your post and solving the problem in about 5 seconds!

Cheers,

RR said...

This is good information. I had a VS 2010 project that stopped building in Release mode (but would still build in Debug!) and this was the problem. Funny thing is that it worked for a while and only began failing recently.

Thanks!

Yevi said...

Thanks Rob. Chalk up some more time saved by your post.

I had to close down Visual Studio and start it again. This may be because the project I was trying to build was WiX and it was one of the WiX DLLs that was blocked.

Anonymous said...

thanks it works like a charm :D

Anonymous said...

thanks a bunch! :)

Anonymous said...

Hey Rob,

I struggled with this issue for close to an hour myself - found your blog and it resolved my problem right away!

Thanks for posting!

Anonymous said...

Thanks a lot !
Merci, vraiment merci beaucoup !

Brett said...

Thank you! I wasted a ton of time trying to fix this too!

Anonymous said...

Thanks for posting this! I wasted a ton of time trying to fix this too but was pleased when I came across your post and was able to fix the issue quickly.

Anonymous said...

You've saved my bacon. Thank you!!!

Anonymous said...

Hi, I'm getting the same error, but I don't have the 'Unblock' under the Properties window. Is there any alternative (e.g. command line) to unblock this dll file? Thanks

Rob Cooper said...

Anon, the only thing I could think of would be to ensure you're logged in as an Admin account. I always am, and the button is always there..