HttpConfiguration missing assembly - asp.net-mvc

I am building a site using MVC4. I couldn't even begin that I am having a strange error. This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace MyProject
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
The error message: The type or name of the assembly 'HttpConfiguration' does not exist in the namespace 'System.Web.Http' (are you missing a using directive or an assembly reference?)
It also doesn't recognize the readonly field RouteParameter. It occurs to me that it may have something to do with the version, my System.Web dll is version 4.0.0.0.
Another additional piece of information is that when I type "using System.Web. ", Intellisense DOES recognize the .Http dll
HOWEVER, in the code, it does not recognize any of its parameters.

I solved it. The issue was that, when I created the site, I updated all packages via Nuget. However, as I wasn´t going to use Entity Framework, I uninstalled it. In order to be able to uninstall that package, it required for me to uninstall Microsoft.AspNet.Providers.Core 1.2 as well... and I did.
This missing package messed things up. I cleared the project and started all over again. I could have also used the Update-Package command in the PM Console and would have restored all lost packages. However, since I had done so much mess compared to the little (next to null) work I had done, I decided to start it all over again.
Thanks anyway!

I encountered this error when cloning an MVC 4.0 application which previously worked for me. My problem was that the Microsoft.Net.Http NuGet package wasn't restoring properly. I solved it from the NuGet console:
Update-Package -reinstall Microsoft.Net.Http

For others facing this issue, my solution was different. Firstly I was downgrading a project from .net 4.5 to .net 4.0, but the symptoms were the same as above:
The type or name of the assembly 'HttpConfiguration' does not exist in
the namespace 'System.Web.Http' (are you missing a using directive or
an assembly reference?)
I stumbled across a blog post which explained that there is a link between Newtonsoft.Json and HttpConfiguration, I removed the reference to Newtonsoft.Json from the project and the packages.config file then re-installed Newtonsoft.Json from the package manager console:
Install-Package Newtonsoft.Json
I was not able to uninstall Newtonsoft.Json from the package manage console due to other dependencies, hence the need to manually remove the reference.
Here's the link to the article: Newtonsoft.Json Hidden Dependencny on HttpConfiguration Breaks Compilation

1.In Solution Explorer, right-click the project node and click Add Reference.
2.In the Add Reference dialog box, select Assemblies tab. And type the “system.web.http” in the search box in the upper right corner.
3.Select the components you want to reference, if it is already selected than first remove the reference than **again Add Reference.
Rebuild the project again. Please let me know if it works. Thank you.

We started experiencing this issue on one of our projects since last week. The project was building fine 2 weeks ago & then all of a sudden started throwing out this exception. No changes were made in in the nuget packages for this project. Even checking out an older revision from SVN didn't result in a successful build.
Out of desperation, we upgraded the solution from VS2012 to VS2013 & lo and behold, it built! We suspect, but were unable to confirm, that a tooling update done in Visual Studio 2013 had affected this library in Visual Studio 2012.
This may not work for all, but there is an option to upgrade the solution, this seems to resolve the problem.

Make sure you compile for Framework 4.5 and not 4.0. That solved the problem for me

when you updated and reinstalled all the AspNet packages from Nuget, and seems there were no appropriate solution - restart of Visual Studio saved me.

I had to update Microsoft.Net.Http and after a long struggle it worked for me
Update-Package -reinstall Microsoft.Net.Http

Yet another scenario. I accept that this is only loosely related to the question as I'm purely Web API. However my search led me here so...
I had an existing project in the solution that targeted Framework 4.5.2.
When I added a new project, it went in as 4.5 as I wasn't paying enough attention. HttpConfiguration duly vanished from the Web API Register method.
Changing the target to 4.5.2 resolved the HttpConfiguration issue. Mind you it also caused some other grief with RouteParameter: now I had two definitions, one in System.Web.Http and the other in System.Web.UI.WebControls. Easy enough I guess.
My feeling is that there is more to this...

Related

Problems after migrating VS2013 to VS2015 in MVC

UPDATED QUESTION
I have a project that I've started in VS 2013 and was setup as the following:
MyMainMvcApp (Containing core Functionality)
MyPlugin (Containing plugable customer stuff)
MyPlugin contains some *.cshtml views as embedded resource and some controllers.
In VS2013 I was able open the Views and i had full Razor Intellisense and no issues when compiling.
IN V2015 the Error List is showing a lot of errors like
Feature 'lambda expression' is not available in C# 2. Please use language version 3 or greater.
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
etc etc
Of course I have all the Assemblies referenced. And the projects even compile.
I believe that VS 2015 is just missing some config stuff in web.config or similar, so that he can resolve the stuff while having the view open in designer.
I have an app.config in MyPlugin project that has been added from Nuget.
I've put the same config stuff as my web.config in there but that didn't help.
As well I copied the MyMainMvcApp\Views\web.config into MyPlugin\Views\web.config that didn't work as well.
Any idea what the issue might be or ideas how to solve it?
I've started MyPlugin as a Class Library in VS 2013 and that worked well. Afterwards I was not able to make MyPlugin work as desired in VS 2015 designer. I've created a new MyPlugin Project as a MVC Project and copied all my code from the old library to the new.
It's a workaround but that solves my VS 2015 problems.
The fact that it's trying to utilize C# 2, is pretty concerning. Make sure your project is targeting the latest version of .NET you feel comfortable with. Since you're using VS2015, go all the way to 4.6 if you like, or if you want something a little more hardened, stick with 4.5.2. Just right-click your project in the Solution Explorer and choose "Properties". Then on the first "Application" tab, change the "Target framework" drop-down to something appropriate.

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.

Bad day fixing references in mvc 5.1 app

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

The type or namespace name 'DbContext' could not be found [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am VERY new to ASP.NET MVC (3) and am having a hard time resolving a build error in Visual Studio:
The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
namespace MyProjectName.Models
{
public class MachineModel
{
// name
[Required]
[Display(Name = "Nom de la machine")]
public string Name { get; set; }
// IP
[Required]
[RegularExpression(#"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",
ErrorMessage = "Donnez une adresse IPv4 valide.")]
[Display(Name = "Adresse IP de la machine")]
public string IP { get; set; }
}
public class MachineDbContext : DbContext
{
public DbSet<MachineModel> Machines{ get; set; }
}
}
The two errors I am getting are:
The type or namespace name
'DbContext' could not be found (are
you missing a using directive or an
assembly reference?)
The type or namespace name 'DbSet'
could not be found (are you
missing a using directive or an
assembly reference?)
What am I missing?
I had the same issue. Turns out, you need the EntityFramework.dll reference (and not System.Data.Entity).
I just pulled it from the MvcMusicStore application which you can download from: http://mvcmusicstore.codeplex.com/
It's also a useful example of how to use entity framework code-first with MVC.
You need to reference the System.Data.Entity assembly in your project, or
install the EntityFramework NuGet package, which will setup everything for you.
Just a quick note. It is DbContext, not DBContext. i.e. with a lowercase 'B'. I discovered this because I had the same problem while intelesense was not working until I tried typing the full name space System.Data.Entity... and name and finally it suggested the lowercase 'b' option:-
System.Data.Entity.DbContext
I had the same problem using VS2010.
I know this isn't really an answer. I just thought it might help someone.
I resolved it by using the fully qualified name for DBContext.
Instead of
public class MachineDbContext : DbContext
I used
public class MachineDbContext : System.Data.Entity.DbContext
and rebuilt the project. Suddenly VS was happy, and I was even able to remove the fully qualified name, and just use DBContext.
I had the same issue... Installing the EF from Package Manager Console worked for me
the command was: Install-Package EntityFramework
If your compiler doesn't recognize
System.Data.Entity.Infrastructure
DbContext
DbSet
et alii,
make sure
you have Entity Framework 4.1 installed on your machine;
in your .csproj file, you have the following reference
<Reference Include="EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
within the element
<ItemGroup>
...
</ItemGroup>
that houses references to other assemblies.
I had the same problem..I have VS2010 express..
(Note: If you see this problem try checking references to EntityFramework.dll ..
May be it is missing.)
The following resolved it for me.
I installed latest MVC 3 Tools Update
then I installed EntityFramework 4.1
or using
NUGet ie. from with Visual Studio 2010 Express
(Tools->Library Package Manager -> Add library Package reference -> Select Online -> EntityFramework)
Strangely that didnt work..So i had to manually add a reference to "EntityFramework.dll"
try doing a search for the dll ..may be here
"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\"
If you already have it..just add a '.net' reference.
Note: If you use NuGet ,it creates a folder "packages" along side your Solution directory.
You will find the "EntityFramework.4.1.10331.0" folder inside it.Within "Libs" folder you will find
"EntityFramework.dll" .
Add reference to it using Browse tab and select the above dll.
I am using Visual Studio 2010 express and adding a reference to C:\Program Files\Microsoft ADO.NET Entity Framework 4.1\Binaries\EntityFramework.dll solved the problem.
This helps really handy:
Select the ProjectNAme project in Solution Explorer.
From the Tools Menu, choose Library Package Manager which has a
sub-menu.
From the sub-menu choose Package Manager Console.
At the console’s PM prompt type install-package EntityFramework then
hit enter.
For step-by-step instructions, see this new MVC / EF tutorial series:
http://www.asp.net/entity-framework/tutorials/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
The tutorial assumes you have installed the latest MVC 3 Tools Update and provides a link in case you haven't.
Your project unable to resolve EntityFramework classes until you not added it in your project.
For adding EntityFramework support you have to follow this steps:
Tools->Nuget Package Manager ->Manage Nuget package for solution
browse EntityFramework
It shows latest stable EntityFramework version.
currently 6.1.3 is latest version
Install it for the selected project.
Download http://www.dll-found.com/download/e/EntityFramework.dll
Paste it in (for x86)
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\
Then Right click on project -> add reference -> select EntityFramework
Bingo......
Visual Studio Express SP1
Right click in Solution Explorer > References > Add Library Package Reference > EntityFramework
Use CTP5 instead it is newer version with some changes in API. You have to add reference to EntityFramework.dll which is installed in CTP directory - default is: c:\Program Files\Microsoft ADO.NET Entity Framework Feature CTP5\Binaries\EntityFramework.dll for 32bit system. On 64bit system it will be placed in Program Files (x86).
This happened to me when I branched code. To fix it I right-clicked my project in Visual Studio, chose manage Nu-get packages, uninstalled EntityFramework, then re-installed it. Problem solved
I just had this issue and none of the other solutions worked for me. I'm using Visual Studio 2010 and I have two projects in my solution: UIProject and DataAccessProject. The UIProject has a reference to the DataAccessProject.
My UIProject was targeting the .Net Framework 4 but my DataAccessProject was targeting the .Net Framework 3.5 for some reason.
I changed both projects to target .Net Framework 4
Uninstalled then re-installed the Entity Framework NuGet Package.
Problems solved. Now I have references to both EntityFramework and System.Data.Entity
i had the same problem.I had to rewrite "DBContext" after adding reference to entityframework and it resolved the problem.
its means that Visual studio was not able to recognize the class automatically and waited for it to be re-typed.
so its best to add reference first and then implement code.
VS 2013 - ultimate used
I had to first uninstall EntityFramework(Uninstall-package EntityFramework (not case sensitive apparently)), then install it again(Install-package EntityFramework), via the PM Console
I had this problem, read the above answer and download the entityframework.ddl but found that it is alreadt referenced. So I added the namespace and problem was solved
using System.Data.Entity;
I am using Visual Studio 2010, SP1 installed
having referenced entityframework.dll both system.data.entity worked.
I had the same error but the problem was just an accidental problem with my model.
I accidentaly put...
public class MyModelDBContext : Context
{
public DBSet<MyModel> MyModels { get; set; }
}
...inside of the model class.
As alternative way you can go HERE - instruction how to install any required dll.
Or you can download NuGet and manage it from VS
Right click your reference and go to manage NuGet packages, then choose online all, then NuGet package source in the search textbox type Entity Framework and install it.
1) Uninstalling Entity Framework from All projects
2) Restart Visual Studio
3) Reinstalling to all required projects
and it started working
There might be a case where you reference everything you need to and you can even Go to Definition by pressing F12 on DbContext class which takes you to System.Data.Entity namespace but you still get this nasty compiler warning. Make sure that the Target Framework of your project and that of the Entity Framework version you are using match. Go to Project->Properties->Application Tab. Change the Target Framework(can't exactly say to which one, trial and error will help.). Just my two cents.
I also get irritated from this issue many times and finally find the solution.Go to edmx file->Update Model from Database->Refresh->Finish.
Clean Solution->Rebuild Solution
you can try on package manager console
PM> EntityFrameWork\enable-migrations
Like the others have suggested:
Add the correct references and directives. But it still doesn't work? Maybe you have the same problem I did:
Have a look below and see if you can tell me what is wrong:
public class PanelLengthContext : DBContext { } ??!
Make sure the class name is not misspelt - (case sensitivity)!
DbContext is the correct spelling.
this is how it should look:
check the spelling. don't waste 20 min of your life like i did. public class PanelLengthContext : DbContext {}
HTH
I have the same issue as you, I'm unable to implement it in the Controller class while it works when I put it in the model class. Add these codes on the top of your controller class
using TimeSheetManagementSystem.Data;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;

NuGet Project > Add Library Package Reference not appearing

I have installed NuGet.
When I try to go to Project > Add Library Package Reference
"Add Library Package Reference" is not under the project menu. If I try to install NuGet again it says it is already installed. My application is an MVC 3 application targeting .net 4.
How can I get this option to appear?
You might also run VS as Admin (Ctrl-Shift-Click) then uninstall NuGet from the package manager dialog. Then update to NuGet 1.1 from http://nuget.codeplex.com and see if that fixes it. ASP.NET MVC is not needed.
Is it possible that some of the extensions of your Visual Studio are causing NuGet to not show the menu or crash? You could try to disable/remove them and then install NuGet from here: http://nuget.codeplex.com/
Besides, there is also a PowerShell-based Package Manager Console. You could take a look on that in case everything fails.
Make sure you have the project selected and not the solution in the solution explorer.
As of May 2012, it's now called "Manage NuGet Packages".
Especially confusing because the screenshots in the NuGet Docs have not been updated.
https://stackoverflow.com/a/9844659/24267
Normally NuGet is installed with ASP.NET MVC 3 so it should appear automatically. Try removing the NuGet package that you have installed and reinstall ASP.NET MVC 3.
Had this same issue, just realized that if you're not on the project (i.e., you have the solution highlighted in solution explorer) that the option for the Add Library Package Reference won't show. Select the project and it's there.
Whoops: Didn't notice that was already mention.
I've just had a similar problem, after trying to install a package over dial-up, which timed out.
To fix it, I renamed the registry key (so that I could rename it back if it didn't work) HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\NuGet, then restarted visual studio and opened a project. The Add Library Package Reference now works and the registry key has been recreated.

Resources