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" etc).
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.
Related
I'm developing a .NET Core project. Yesterday, Web.CodeGeneration was updated automatically. After the update, I get an error when I try to add new view to my project:
"Scaffolding Failed"
"Could not load information for project X"
I tried to remove and re-install all nuget packages again, and I checked package versions and all of them are 6.0.9 so, same version.
I tried to create a new project to test "add view", but when I install Entity Framework Core packages with web.codegeneration in the test, project, I again get the same error.
How to fix it?
Unload all your class libraries/other projects except for your web application then try re-adding any scaffolded items. This is the current workaround that works on my end, at least until this bug gets fixed.
Update:
Bug is patched with the Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.10
EDIT - Fixed in 6.0.10, if you are experiencing this issue make sure you update the packages.
The issue has been reported and is a bug in the scaffolding code.
The suggested workaround is to scaffold in a new solution/project with the same name(s) and then copy the files over:
Make new project with same solution and project name and add DB context and
other necessary thing than scaffold then the new added files add in the
main project you are making, now you are good to go.
Unloading the linked projects as suggested by others works, provided you don't have your models in separate class projects.
Otherwise we will have to wait
Remove all project references in the project you are working on, then you won't get error. After adding Areas etc. you can again add project references
If you create references to other projects, the error returns. Importing the libraries works, but if you reference them it gives an error
This isn't actually an answer, but I'm too new to leave a comment. I just wanted to pass along some information that I found useful.
I was having an issue scaffolding my MVC Controller, with views, when my Library was unloaded, even though I kept the reference. This bug is also being discussed on GitHub, and Deepak Joy Jose uploaded this video showing the workaround: Scaffolding Workaround It's for identity scaffolding issues, but the same logic applies to controllers. It's a long workaround, but it did work for my issue.
I want to start off by saying I've been really hesitant to ask this question because it seems like it should be such a simple thing, however, I've scoured the internet and all I can find is the basic solution to something similar to my issue.
I have a nuget package that is v 1.30 and I'm trying to update it to 1.41. I've used the NuGet UI and I've also used the Package Manager Console to do this multiple times with small variations and I continue to get the same result. After I do something like "Update-Package PackageName" my package updates correctly. NuGet deletes the old reference and the old files and the 1.41 version is referenced by all the projects in the solution using that package. When I look at the Code, there are no syntax errors, Visual Studio seems to think the reference is just fine and I can even ctrl+B (re#er) to 'go to declaration.' However, when I build, every place I have 'using PackageName' in code throws an error that says
"The type or namespace name 'Common' does not exist in the namespace 'PackageName' (are you missing an assembly reference?)"
I have tried cleaning my solution. Then building. I've tried resetting through Git, cleaning the solution, updating then building. I've tried updating, cleaning, deleting the reference, building (will get the errors obviously), then adding the reference back in manually and building. Every time I try I get the same error. It's only happening for my Core project, but all my other projects depend on the Core, so they won't build anyway. I'm assuming this issue would still present itself if they were able to build. I've looked at the properties of the reference, it is referencing the v 1.41 file and it is set to Copy Local = True (I read somewhere someone suggested looking at that).
I'm open to suggetions for things to try. I don't have any code changes that I'll lose of I do a Git Reset, so I can try whatever.
Thanks Internet.
After trying several different things, we figured out it was a version mismatch with ASP.NET. Someone had pulled in a newer package that required updating to ASP.NET 4.5 and the solution I was working in was still ASP.NET 4.0. After updating to 4.5 the problem with the references was resolved. But we ran into some new Automapper issues. One thing after another. However, if you're banging your head against your desk in frustration because of this problem, check the framework version of your projects and the package you're updating.
Googling this issue, I've tried all the answers to my problem with no change.
I have a small MVC e-commerce app I am building for my company. It is divided into two projects: Domain and WebUI. WebUI is obviously dependent on Domain and my build-order reflects this. I've checked target frameworks for both projects and they match (4.5) and I have EF 5.0 added.
After building the basic product presentation/catalog and cart code I want to implement users so I can build the order/store functions.
Everything is working fine until this point.
I run "Enable-Migrations" so I can write my own membership/user code and use the DB I have setup so future context changes target my DB instead of the defaultOCnnection.
Enable Migrations inserted the Migrations folder and Configuration class. Ran with no errors produced. "Checking if the context targets and exisiting database ... Code First Migrations enabled for project *.WebUI."
When I attempted a Build after running Enable-Migrations, I received a number of errors stating that The type or namespace 'Mvc' does not exist in the namespace 'System.Web' in the Domain project (my product class) and one error 'Could not resolve reference. Could not locate assembly "System.Web.Mvc, Version 4.0.0.0 ...." Check to make sure the assembly exists on the disk ..." And of course an error from WebUI that it could not locate the Domain.dll (because Domain.dll fails to build).
How did running enable-Migrations cause this?
How do I resolve this? The dll is on the disk, right where the properties say it is, Reference included, Local Copy=true ....
I'm really at a loss to figure this one out ....
Strangely, I encountered this error two days ago on one of our machines, the only difference being that we are running EF 6.1.1. I used ReSharper to check that nothing in our domain project was using System.Web.Mvc and I removed the reference. I couldn't figure out how it got there anyway.
We ran enable-migrations maybe a couple of years ago on this code base, so it would seem unlikely that our issue was caused by that.
For your part, there really shouldn't be much of a reason to have a reference to System.Web.Mvc in your domain code, so perhaps you could look at moving whatever code is depending on that DLL into your web project, if it can't be outright deleted, then remove the DLL reference itself?
I know this doesn't explain why it doesn't just work. That might have something to do with assembly redirects in the app.config file, perhaps. Maybe it's redirecting to v5, which isn't there?
After I build a few of my references, which are present in the project and accessible through intellisense before the build is performed.
Unfortunately none of my projects are set to target Client Profile, as answered in this thread.
The type or namespace name could not be found
This seems to be the most common cause, does anyone know what else other than this can cause the same issue?
Edit:
The Types that aren't found are all from the referenced DLLs. I have the correct using directives for these and they are present in the resource folder, however they become underlined red after a build (I did try cleaning to).
My initial thought was the framework (the project is on v3.5), but I checked all my resources working or otherwise all where on v2 bar a few (working ones) on v4 which I removed temporarily to make sure we're causing issues.
Unable to access the project from my current location but will post any requested specifics as soon as I can.
edit:
Resolved the issue by deleting all of the custom class libraries... found and rebuilt each of their projects then added the new DLLs back into the project. Stored libraries weren't very organised, so I probably have some confliction between old/new versions.
Have you read the warning in the error list? You might need to install nuget package used by the referenced projects
for me the error warning was
All projects referencing "project file" must install nuget package Microsoft.Bcl.Build.
Are the projects being built correctly ?
Sometimes, you need to manually generate them (right click on them, generate), before being able to run a full build.
I dont exactly know why, but this might be the way to go for you.
~A few simple things to try before getting into more complicated water...
Try clicking:
Build->Clean Solution
Build->Build Solution
If this doesn't work, check your using statements are all there and correct, check your references all still exist.
I had a similar issue today, and I thought I would mention it here in case it helps someone else out. In my case, I have a VB.net Class Library which is referenced by a C# class library. The solution would build fine, but in the IDE, as soon as I started editing a file in the C# project, I would get errors about not finding a reference to the VB.Net library. It turns out that the VB.Net class library had a reference to System.web (lowercase w). I'm not sure how that came about -- but the solution was to delete that reference and replace it with a reference to System.Web (uppercase W).
Make sure all the projects in your solution have the same "Target framework" value
answer = The problem was simple we had a common lbrary with functions. the service was a new functionality that had been attempted by someone in this common, and was still present in the one referenced by the project.
this caused the project to have 2 identical namespaces (one in the common dll and one in the service).
We had a problem adding this reference at first because of the rights the service had in IIS. we fixed that problem however, when adding the reference again it seems to only partly add the reference. It does appear in the service list but not in the app config, and it can't be used (intellisense doesn't find it nor does manually typing work).
if we try this in a diffrent project it does add perfectly and wehave tried deleting anything we can find about the reference before readding it (the subfolder, opening the project in notepad and deleting all references there) but nothing seems to work.
when deleting and readding a diffrent service to this project in similar ways and that works and we can add it to diffrent projects in the same solution, just not in this project.
Anyone have any idea why this could happen and possible solutions?
EDIT: When we recreated the project in the same solution and dragged all classes etc over we can add and remove this reference as we want. although this would count as a solution i would actually like to know why things happened like they happened rather then recreate projects when things seem to get stuck. Is there a cache or something in visual studio that could cause this?
Also at times it takes longer (or never finds it) to find the service then at other times where it does so in <1 second. the best way to get it seems to stop and start the search. not sure if it is related but it does seem like a difference between my PC and the other one we use as well.
Edit2: we have also tried deleting the services folder, re-adding services recreates the folder and adds this reference it does not work. if we add a different service after the deletion of the folder, that reference does work. adding the reference we want to add after that does not make it work.
Edit3: in an additional project, i can add it once where it works however deleting the reference and then re-adding it makes it so it doesn't work again. a similar reference to this one i can delete and re-add as many times as i want within the same project and it keeps working. this one reference keeps not being found when re-added after a delete and giving the "Type or namespace can't be found" error.
We also tried changing the solution and projects GUIDs and still, it does not add the service reference correctly in the project.)
**Edit4: When turning off the Reuse types in referenced Assemblies in Configure Service Reference.. Dialog box visual studio adds the information to the Reference.cs page leaving that page empty. unticking this box does add all references to that file and makes the service reference work.
However i can use most of the reference, i am missing the entry point meaning i can't run it.
this is the dialog box where i untick to be able to get a tad further.
When I worked with Service References I found out that in addition to remove the Service Reference Folder I had to remove the reference in app.config, along these lines:
<system.serviceModel>
<bindings>
a lot of lines...
</client>
</system.serviceModel>
Could be a help...
Gorgen
Finally really solved this. as Mike Cheel said in his comment. ill reprovide the link
The problem was simple we had a common lbrary with functions. the service was a new functionality that had been attempted by someone in this common, and was still present in the one referenced by the project.
this caused the project to have 2 identical namespaces (one in the common dll and one in the service).
So, simply, build a new common dll, added it to the project and now it works perfectly.
I would start by deleting the whole "Service References" folder that is generated when Visual Studio is adding service reference.
Did you try it?