Could not load file or assembly HRESULT: 0x80131515 (When adding controller to MVC project that has assembly references on network drive)
Asked Answered
A

11

79

I've seen this: VSTS 2010 SGEN : error : Could not load file or assembly (Exception from HRESULT: 0x80131515) and none of the answers work. It also doesn't appear when I build or anything. I can run the project fine, it happens when I try to add an entity framework templated controller:

controller settings

Then I get this error:

error message

All project files are on my network share because that is where My Documents resides for our work. Here is what I tried:

1) Turning Generator Serialization Assembly in project settings to on, off, and auto.

2) Adding sgen.exe.config to C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools with the following code:

<configuration>
 <runtime>
   <loadFromRemoteSources enabled="true" />
 </runtime>
</configuration>

3) Tried to unblock the assemblies, but I had no unblock option in the properties tab. no unblock option

None of these solutions work. Does anyone have any idea how I can fix this??? This error occurs for any custom assembly from nuget or my own projects due to their location existing on the network space, but only when trying to add an EF templated controller. I can build and run the program fine.

Apices answered 15/12, 2011 at 17:48 Comment(4)
From How to: Use an Assembly from the Web in Visual Studio "The Unblock button will not appear if the assembly is already unblocked and available." So I'm guessing that's why you didn't get that option. As a side note did remember to restart Visual Studio?Shock
@ConradFrix Yes I did restart multiple times, still no dice =(.Apices
Try adding your <loadFromRemoteSources enabled="true" /> to C:[Visual Studio 2010 Install Dir]\Common7\IDE\devenv.exe.config and see if that helps.Stcyr
@Stcyr Yes sir that did the trick! Please post is as an answer so I can give you rep!Apices
S
84

Try adding your <loadFromRemoteSources enabled="true" /> to C:\[Visual Studio 2010 Install Dir]\Common7\IDE\devenv.exe.config directly below <runtime> and see if that helps :)

Stcyr answered 16/12, 2011 at 15:1 Comment(6)
Spot on. I'm attempting to do Visual Studio 2010 builds within Parallels while maintaining the actual source on the shared OS X drive, and unit tests refused to run without this alteration. I also tried changing sgen.exe.config with no luck - only this solution worked.Masterly
This solved a problem loading an assembly from PowerShell v1 with Import-Module, for me as well. Thank you!Mohammedanism
Just opening the file properties in windows explorer and clicking on 'Unblock this file' should also solve the problem. Did for me at least.Tartlet
My error was coming from InstallUtil - I had to add <runtime><loadFromRemoteSources enabled="true" /></runtime> to C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe.config and it worked.Trapezoid
@Tartlet - WOW, THIS ACTUALLY WORKED!Lenorelenox
Excellent ! Thanks a ton !Retain
K
139

I just needed to click "Unblock" in the file properties dialog in Windows Explorer.

Kellar answered 2/1, 2013 at 3:43 Comment(2)
Where this property found?? In solution properties or any where else ? Help please !Beebread
In Windows Explorer, right click on file, click on Properties.Kellar
S
84

Try adding your <loadFromRemoteSources enabled="true" /> to C:\[Visual Studio 2010 Install Dir]\Common7\IDE\devenv.exe.config directly below <runtime> and see if that helps :)

Stcyr answered 16/12, 2011 at 15:1 Comment(6)
Spot on. I'm attempting to do Visual Studio 2010 builds within Parallels while maintaining the actual source on the shared OS X drive, and unit tests refused to run without this alteration. I also tried changing sgen.exe.config with no luck - only this solution worked.Masterly
This solved a problem loading an assembly from PowerShell v1 with Import-Module, for me as well. Thank you!Mohammedanism
Just opening the file properties in windows explorer and clicking on 'Unblock this file' should also solve the problem. Did for me at least.Tartlet
My error was coming from InstallUtil - I had to add <runtime><loadFromRemoteSources enabled="true" /></runtime> to C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe.config and it worked.Trapezoid
@Tartlet - WOW, THIS ACTUALLY WORKED!Lenorelenox
Excellent ! Thanks a ton !Retain
H
11

Just as an additional solution, we had an issue like this recently. The solution turned out to be unblocking the files, but with a twist. We copied the files to our server in a zip file. When we extracted the files from the zip archive, they were already blocked. We were not able to unblock the files. We would click the unblock button, then OK, and when we looked at the properties, they were still blocked.

What we had to do is delete all the blocked files, unblock the source zip file, and then extract the files. At that point, the formerly blocked files were unblocked, and the application ran fine. Hope that helps someone avoid some frustration.

EDIT: I believe you also have to be running windows explorer as administrator to be able to unblock files.

Holoenzyme answered 19/1, 2015 at 17:36 Comment(1)
This trick worked for me without running Explorer as Adminstrator.Tussah
C
9

This issue comes from the fact that some required files are on "untrusted location" such as the network or a shared location (even on the same computer). If the location is on the same computer, you can use the subst command line option.

Catchall answered 19/7, 2012 at 17:36 Comment(0)
F
9

These solutions did not work for me either.

In my case, I was accessing files on a mapped network drive. The solution for me was to add my network IP address as a trusted drive by doing the following:

  1. Control Panel
  2. Network and Sharing Center
  3. Internet Options (bottom left of window)
  4. Security Tab
  5. Select "Local intranet"
  6. Click "Sites" button
  7. Click "Advanced" button
  8. Add the IP of your network drive to the zone.

Not sure what made this work over all other options, but this is what solved the problem for me. All project and solutions now build with no issues.

Fushih answered 12/11, 2015 at 19:14 Comment(4)
Last answer here, but this is the only one that worked for me.Calcifuge
Thank you sir - you are a gentleman and a scholar. This is exactly it. I'm using VirtualBox and my project sits in a shared folder, which Windows sees as a network drive.Actinomycete
I'm using Hyper-V and loading my project via network share - this was the only solution that worked for me.Considered
Right answer for me too. On a Mac, I launch Visual Studio in a VMWare virtual machine and my project files are mapped as a network drive. Adding vmware-host to the zone solved the issue.Guileless
F
8

I saw from other forum regarding this issue, and here is the solution someone posted: On the property of the project that contains the DLL assembly that would not load, go to the Build setting, and way at the bottom where it says "Generate serialization assembly:", the default is Auto. Set that to Off. Your solution should then build OK.

This happened to me when I had the API in a webform solution with multiple project. It worked OK on a single-project solution MVC.

Familial answered 13/8, 2013 at 16:54 Comment(0)
P
2

None of these solutions worked for me. Instead, I found the way by making sgen.exe.config via https://mcmap.net/q/202483/-vsts-2010-sgen-error-could-not-load-file-or-assembly-exception-from-hresult-0x80131515

Proconsulate answered 1/5, 2015 at 1:36 Comment(0)
H
2
  1. I just needed to click "Unblock" in the file properties dialog.

  2. Please check if your file read only, then uncheck it and do the first step (before wasting further time on this :) )

Hennessey answered 14/12, 2016 at 23:14 Comment(1)
(+1) Aside from run as Admin, This should be the first thing anyone should check before proceeding to permissions stuff. and make sure you unblock everything which are related to your services (anything that won't automatically open any kind of access permission dialog box will fail when the permission is not granted. e.g. windows apps will automatically ask the user to grant access but services can't).Hypercorrect
R
2

The other answers here helped me to figure out this issue in PowerShell. Run Unblock-File <filename> to allow it to be accessed by the script being executed.

Rheingold answered 2/2, 2018 at 18:33 Comment(1)
My working environment had some permission issues so I had some troubles unblocking via File Explorer. This worked like a charm thank you.Marmalade
G
1

Unblock all files with Unblock-File -Path "*.dll"

Groh answered 15/8, 2023 at 9:1 Comment(0)
W
0

Try to unblock the file desbloquer.

This solved my problem.

Waac answered 7/6, 2017 at 15:18 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.