Add controller after recent software update with dependency error

Since installing the latest updates for MVC3, adding a controller through the "Add Controller" context menu often leads to an error:

Failed to 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 specified file.

Or simimlar (sometimes another dependency, for example, "Mono.Addins", etc.).

The links to which he complains are not directly needed by the project, but refer to other links that this project has. The project creates find without references, but Add Controller fails.

Adding the link mentioned in the error also does not fix it. Even after adding a link to Newtonsoft.Json (with the correct version and token), the error remains.

I suspect this due to the reflection of the Add Controller dialog box to provide a list of model types that can be used, but I cannot understand why these are still errors even after adding the requested link.

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

At the moment, my job is to manually add controllers and then add non-strict types and edit them manually, but this is becoming very frustrating - especially since I cannot use our T4 client templates for forest and controller views.

Has anyone else experienced this since the update and knew how to fix it?

+6
source share
5 answers

I had the same problem with protobuf.

This means that one of the projects you are referencing has a dependency on Newtonsoft.Json, I assume that it is through attributes.

When VS tries to reflect the type of your assemblies by offering you model classes in the dialog (Add Controller / Add View), it cannot find Newtonsoft.Json to find out what it reflects by adding a link to Newtonsoft.Json in your MVC project, fix this .

0
source

Drop all your dependencies and upgrade your DLLs to the version you want to use again. This fixed it for us, it happened with several different libraries, and not with one.

0
source

I finally decided. I think the problem may be in different places. In my case, I added models to my domain, but I forgot to add contexts for these new models; such things as

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

I did not have an error at compile time, and I did not use these models in the solution, so there were no errors at runtime. A little by chance I found this. Another thing I should mention is that I rebooted my machine in the meantime. I do not know if this has affected the situation, but I rather believe that the problem is related to the missing contexts.

0
source

This has nothing to do with updating tools. I had a similar problem, and I fixed it by restoring the entire dependency tree, starting with "leaves" (i.e. Projects that have no dependencies). There was already a similar question, my answer is: fooobar.com/questions/888697 / ....

0
source

Thanks, that helped me. I recently added a library called OAuth2.MVC to the MVC4 Web Api project, and then this error started. Oauth2.MVC depended 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 is open source) and upgraded Newtonsoft.Json version there to 4.5.0.0, rebuilt it, and then re-imported the link into the MVC4 Web Api project, and then I could add the controller without error.

0
source

Source: https://habr.com/ru/post/888688/


All Articles