开发者

MVC 2 to MVC 3: MvcScaffolding fails due to "could not load file or assembly" error

开发者 https://www.devze.com 2023-03-14 12:34 出处:网络
Setup: I am using MVC 3, EF 4.1, Visual Studio 2010 SP1 with Power Tools updated to latest version. With the above installations, I don\'t need the NuGet packages that were required previously.Every

Setup:

I am using MVC 3, EF 4.1, Visual Studio 2010 SP1 with Power Tools updated to latest version.

With the above installations, I don't need the NuGet packages that were required previously. Everything is RTM.

The project has been upgraded from MVC 2 to MVC 3. I initially tried the upgrade tool, but that gave me grief, so I did it manually as per the instructions in the MVC 3 Read Me file.

Problem:

When trying to use the new scaffolding of controllers and views for CRUD functionality (against Code First DbContext), the scaffolding fails with the error:

Could开发者_运维问答 not load file or assembly 'file:///C:\[PATH TO MY APP]\bin\Lanap.BotDetect.dll'
     or one of its dependencies. Operation is not supported. 
    (Exception from HRESULT: 0x80131515)

Question:

Lanap.BotDetect is a Captcha control. It works fine and is there, I use it in other pages no problems, the solution compiles, etc, etc. So there is no problem with this dll.

However, this error is stopping me using the new scaffolding capabilities.

I can't see what it has to do with the scaffolding of a new controller and its views, so there must be some configuration that is wrong.

Any suggestions as to where I can look? Googling has drawn a blank.


EDIT 1:

I am trying to see the failed assembly binding using Fusion Log as suggested in a comment. No failed binding showing (but that might be my fault) but the question remains:

Why would MvcScaffolding NEED to load the Captcha .dll at all? It is just scaffolding a controller, and nothing in the T4 says anything about this .dll

(NOTE: I haven't edited the scaffolding T4 code)

EDIT 2:

I tried removing the reference to Lanap.BotDetect, and the error changed to not being able to open the config file that has the connection strings (I shunt the connection strings out to a db.config string, just gives me less visual pain when looking at a config file).

I am giving up on scaffolding on this app. It works in clean, new apps, but not this one where there is a lot of pre existing code.


I found another solution to this. Turns the issue for me was that the issue was it was being built over a network drive. So when I moved the project over to a location local to my machine and rebuilt the project it corrected everything. I detailed everything with screen shots and here...

http://ryandunn.co/mvc-growing-pains-could-not-load-file-controller-dll

Put simply check the location of your project and move it to C: after that a quick rebuild had me back and working normally.


So I know that you have moved on but I ran into the same problem and just found the solution. It turns out the error is due to the assembly not being trusted i.e. you downloaded it from the internet.

You can right click the .dll and unblock it to fix the problem. For info on how to unblock see the following

http://blogs.msdn.com/b/brada/archive/2009/12/11/visual-studio-project-sample-loading-error-assembly-could-not-be-loaded-and-will-be-ignored-could-not-load-file-or-assembly-or-one-of-its-dependencies-operation-is-not-supported-exception-from-hresult-0x80131515.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消