开发者

Add Controller after recent tools update fails with dependency error

开发者 https://www.devze.com 2023-03-07 22:42 出处:网络
Since installing the recent tools update for MVC3 adding a controller through the \"Add Controller\" context menu is often failing with the error:

Since installing the recent tools update for MVC3 adding a controller through the "Add Controller" context menu is often failing with the error:

Could not load file or assembly 'Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

Or simimlar (sometimes another dependency, such as "Mono.Addins" e开发者_开发问答tc).

The references it complains about aren't needed by the project directly, but are referenced by other references this project has. The project builds find without the references, but Add Controller fails.

Adding the reference mentioned in the error doesn't fix this either. Even after adding a reference to Newtonsoft.Json (with the correct version and token) the error remains.

I suspect this due to the reflection the Add Controller dialog does to provide a list of model types that can be used, but I can't understand why it still errors even after adding the requested reference.

The "Add View" dialog is slightly better but still fails. The dialog opens, but when you tick "Create a strongly-typed view" the dialog immediately closes.

At the moment my work around is to manually add Controllers, and to add non-strongly types views and edit them by hand afterwards, but this is becoming really frustrating - especially since I can't take advantage of our customer T4 templates for scaffolding views and controllers.

Anyone else experienced this since the update and know how to fix it?


I had the same problem with protobuf.

It means that one of the projects you reference has a dependency on Newtonsoft.Json, my guess is that it's via attributes.

When VS tries to reflect on your assemblies' type to offer you model classes in the dialog (Add Controller / Add View) it can't find Newtonsoft.Json to figure out what it's reflecting, Adding a reference to Newtonsoft.Json to your MVC project should fix that.


Drop all of your dependencies and update their dlls to the version you want to use again. This fixed it for us, was happening to a couple of different libraries, not just one.


I finally solved it. I guess the problem can reside in different places. In my case, I had added models to my domain, but I had forgotten to add contexts for these new models; things like

public DbSet<Region> Regions { get; set; }

I had no error at compile time, and I was not using these models yes in the solution, so there was no error at run time either. It is a bit by chance that I found this. Another thing I have to mention is that I rebooted my machine in the meantime. I don't know if this affected things also, but I rather think the problem was due to the missing contexts.


This has nothing to do with the tools update. I had a similar problem and fixed it by rebuilding my whole dependency tree, starting from the "leaves" (i.e. projects that have no dependecies). There was a similar question already, my answer to it is here: https://stackoverflow.com/a/6627505/342838.


Thanks, this helped me. I had recently added a library called OAuth2.MVC to my MVC4 Web Api project, and then this error started occurring. Oauth2.MVC had a dependency on Newtonsoft.Json version 3.5.0.0, and my project already had version 4.5.0.0. I went back to the OAuth2.MVC project (it's open-source) and upgraded the version of Newtonsoft.Json there to 4.5.0.0, rebuilt it, and then re-imported the reference into my MVC4 Web Api project, and I could then add a controller without the error.

0

精彩评论

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