Bad day fixing references in mvc 5.1 app - asp.net-mvc

I have a problem with visual studio and nuget package manger
I was running very good when suddenly the project stopped to compile telling me that the ApplicationDbContext should derive from DbContext or something like that, i couldn't see the problem so i cleaned my solution rebuilt the project it compiled but had stupid runtime erros so I searched stackoverflow and the web And I found out it was a reference error in the first place so I removed the bin folder as described here in this question
higher version than the referenced assembly
then it went all bad i tried to remove all the references and re-install them manually but nuget PMC kept telling me that my project already had a reference to that assembly,, I closed Visual Studio re-cleaned the project and done that once again with no results!
so the question here would be how to re-install the latest version of everything to be compatible with asp.net MVC 5.1 without getting a message telling me that my project has a reference to those assemblies nonsense !

I had this happen to every one of my projects I upgraded to MVC 5.1. I had to add binding-redirects to my web.config. With the Package Manager Console it was easy.
http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference#Add-BindingRedirect

Related

The name 'Url' does not exist in the current context error VS2017

Getting an error The name 'Url' does not exist in the current context error in asp.net whenever I open a .cshtml file in my web project.
I should note that I got this solution fresh from our source repo and other developers tell me they don't see this issue.
Web project has a referenced to a nuget package and when I look at System.Web.MVC it's Mvc.4.0.40804
Things I've tried based on posted solutions:
1) Unloaded project and deleted .user file and did a clean and rebuilt.
2) Deleted temp ASP files in the .net framework directory.
There are a lot of other solutions saying to move views or adding to web.config file, but if other developers using same solution aren't facing this - I'm thinking it's machine specific.
I don't see any reference errors in the web project.
When I installed VS2017, I just did the ASP.NET development. So, i have no gotten another version of MVC. Could it be that?
Thanks,
Brian
So I ended up modifying my VS2017 install and under ASP.NET and web development, I uninstalled that and reinstalled and made sure ASP.NET MVC 4 was checked off under Optional.

Upgrading to Visual Studio 2015 renders intellisense broken for project

I've been through a lot of similar issues, but could not find anything that worked for me.
I'm upgrading my IDE from the VisualStudio for Web (v10) to Visual Studio 2015 (v14, I guess) Community Edition.
The main project that I'm trying to use on the new IDE is a MVC 5 (5.2.3), with EF 6.1 (6.1.3) and a bunch of other stuff.
Problem is: When opening the project on the new IDE, everything looks fine (it even compiles and work). I got the MVC context menu working on the project explorer (showing the "Add Controller..." and "Add View..." when appropriate). Only (really annoying) thing is the Razor Intellisense.
When I do open a View file (.cshtml) I receive warnings on several helpers, some of the "using" are greyed out (even though they're supposed to be needed) and the #model myModel is shown like everything after the #model directive is not razor (it's treated like HTML by the intellisense coloring).
What I've already found and tried:
I've already tried to clear the UserData from the vs (devenv /ResetUserData)
I've already tried to run the VS2015 in safe mode
I've already tried to run VS2015 as Administrator
I've already tried to set the Project's target framework to 4.5.1 (used to be 4.5)
I've already tried to open the project on Visual Studio Community 2013 saving it there before trying to use it on VS2015.
When creating another MVC project from the VS2015, everything works fine.
Here's an example of the annoying issue:
Ok, finally got it.
Posting what I found out believing it may help someone else:
What seems to cause the problem mentioned is the fact that the project was created on an old MVC version (with older Razor, EF, etc).
As stated in this answer: Visual Studio 2015 Razor View MVC Types not recognized, VS2015 tools may not work for older MVCs.
The solution is to update all your packages to [at least] the minor versions accepted on newer MVC (5?). To do so you can use the list in this website: http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2.
Once everything is up-to-date, open the web.config files located on root of your application and on the Views folder. In there, you will probably find some references to the older versions of MVC and Razor. Update those versions values (all of them) to match the updated versions of your packages (you may create a new empty MVC project on the new Visual Studio and check for those values as a hint of what they should be).
This step is the catch! Since, even if you update you project's packages, some web.config references may still mention the original versions.
Clean the solution (Build > Clean Solution) and close the project. Reopen and compile it. Now [hopefully] everything should be working fine.
[Edit]
One more thing: If your project was also updated from Framework 4.5 to 4.5.1 during this IDE transition, you should also install a NuGet package called "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" (as stated in https://support.microsoft.com/en-us/kb/3025133).

Strange issue with System.Web.Mvc losing its reference when checking out of TFS

I'm working with another developer on a project and everything has been working great until today. Now when I check out the solution to my Visual studio 2013, my reference to System.Web.Mvc is lost and I have to manually re-add it.
When I check in and she checks out, the same issue occurs for her. The path to the assembly is the same on both of our machines:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC
4\Assemblies\System.Web.Mvc.dll
but for whatever reason, we're not in sync. As I said above, it was working great until today so something must've changed...but I have no idea what???
Any suggestions/ideas of what to look for to resolve this?
TIA
This issue occurred due to a Security update that incremented the version of MVC. So if you had References in your project pointing to the hard drive where the 2.0/ 3.0/ 4.0 version was. Your project was needing that particular version. Another way to solve this is to use Nuget to update references.
This is a post from Microsoft regarding the issue:
http://blogs.msdn.com/b/webdev/archive/2014/10/16/microsoft-asp-net-mvc-security-update-broke-my-build.aspx

NuGet package messed up project

I installed this NuGet package through the Package Manager Console. It messed up my project and since System.Net.Http is missing so it is impossible to build my ASP MVC WebApi project anymore.
I tried removing references to System.Web.Http.WebHost.dll from the project and adding the previous one (that used to work) and regardless of which I used now, the Http part of the namespace can't be found.
Have you ever had this problem ? I read trashing the project and starting from scratch solved it for others, but that's not really a solution in my book.
Any ideas ?
Try to run this in Package Manager Console:
Update-Package Microsoft.AspNet.WebApi.Cors -Reinstall
If you get any errors, comment below.
I trashed the project and restarted a new one (Web API). I'm just drag and dropping class files back in the new one.
It wasn't under source control. That'll teach me.

Get InvalidCastException with Glimpse, even though it's not installed. How do I fix this?

I had a Visual Studio 2012 project that I imported into Visual Studio 2013. I upgraded Entity Framework to version 6. I got the following error when I started the first time: Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'. Since this was a prototype app, I wasn't concerned about Glimpse, so I uninstalled it via NuGet, which removed the error and I carried on.
Now, I'm deploying to Azure websites and I keep getting that error!
Glimpse is uninstalled.
It works fine in release and debug locally.
I tried putting System.Data.Metadata.Edm.MetadataWorkspace.ClearCache(); in the Application_Start like this says. (Even though I don't run queries in Application_Start
I suspect I have a caching problem on Azure, but I'm not sure. How do I get the Azure deployment to remove Glimpse like the local install has?
Update: "Fixed"it by deleting the azure website and recreating it. Would still love to hear how to do with this without going with the nuclear option.
This is a bug and is fixed in the release that will hopefully be going out tomorrow - see here for more details https://github.com/Glimpse/Glimpse/issues/540.
I also faced this error and later on found the resolution.
Issue was that I had MVC5 and EF6 based solution and i had imported Glimpse.mvc4 and Glimpse.ef5 packages and they were incompatible i think .
Once i upgraded to Glimpse.EF6 and Glimpse.MVC5 it started working fine.
also had the same one, when I opted to remove Glimpse.
you can prevent this by deleting the bin/ and obj/ folders from your project folder(s) as Glimpse is copied to your bin during debugging.

Resources