ASP.NET 5 Web api template, unresolved reference System.Web - c#

My ASP.NET 5 Web api project fails to build when adding a reference to System.Web
Steps to reproduce problem:
Create a new ASP.NET Project
Select the ASP.NET 5 Web API template
Right click references and add System.Web
Add using System.Web; to some class
Exact error code:
CS0234 The type or namespace name 'Web' does not exist in the namespace 'System' (are you missing an assembly reference?) Stackoverflow.DNX Core 5.0 D:\Git\Stackoverflow\src\Stackoverflow\Startup.cs 10 Active
What I tried to do next is add:
"dnxcore50": {
"frameworkAssemblies": {
"System.Web": "4.0.0.0"
}
}
To the project.json file under the "Frameworks" tag after restoring packages this resulted in an unresolved dependency issue.
The solution DNX SDK version is: 1.0.0-rc1-update1 (which is the only option listed in my Visual Studio)
After a quick google search for any workaround left me empty handed.

Asp.Net 5 is no longer based on System.Web and there is not .net core compatible implementation of it. But there are many nuget packages so probably you will find the expected feature.
For example:
Instead of System.Web.Mvc, you need to add Microsoft.AspNet.Mvc nuget package to your project and you will be able to use the controller base class.

Related

The type or namespace name "HTTP" doesn't exist in the namespace system.web error in .net 4.6.2

I am new to .net/C#. I am trying to build a project but getting a lot of missing reference error.
When I am trying to install the packages like mentioned in example, I am getting error that it already exists in the project.
PM> Install-Package Microsoft.AspNet.WebApi.Core
Package 'Microsoft.AspNet.WebApi.Core.5.2.7' already exists in project 'XXXXXXystemApi'
Time Elapsed: 00:00:16.0349189
Also, as in below screenshot, I see that there are few references which have a little warning signs which might be pointing towards what is wrong with my setup.
The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
I tried to Add references to the project but I am not seeing any entry for System.Web.Http under add reference dialog.
How do I fix all this ?
Try running
dotnet restore
in the Package Manager Console
Also, unloading and reloading the project has worked for me before
(Right-click on the project name in the Solution explorer to unload and reload)
Here is what finally solved my problem.
use NuGet and downgrade a version of library you are having issue with ; then re-install the right version. Accept Licenses (which is probably what was needed). Important: close and reopen visual studio.
Reference link : solution ref

Microsoft Azure C#: The type or namespace 'Cosmos' does not exist in the workspace 'Microsoft.Azure'

I am trying to read a Cosmos DB within my Azure C# v2 Function. In order to do so, I need the following import:
using Microsoft.Azure.Cosmos;
However, I receive the following error:
Using directive is unnecessary. The type or namespace 'Cosmos' does
not exist in the namespace 'Microsoft.Azure' (are you missing an
assembly reference)?
This seems strange, considering that I have already added the package view the dotnet CLI:
C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring>dotnet add package Microsoft.Azure.Cosmos --version 3.11.0
Determining projects to restore...
Writing C:\Users\t-henzhu\AppData\Local\Temp\tmp529E.tmp
info : Adding PackageReference for package 'Microsoft.Azure.Cosmos'
into project
'C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj'.
info : Restoring packages for
C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj...
info : CACHE
https://api.nuget.org/v3-flatcontainer/microsoft.azure.webjobs.host.storage/index.json
warn : Microsoft.Azure.WebJobs.Extensions 3.0.5 depends on
Microsoft.Azure.WebJobs.Host.Storage (>= 3.0.11) but
Microsoft.Azure.WebJobs.Host.Storage 3.0.11 was not found. An
approximate best match of Microsoft.Azure.WebJobs.Host.Storage 3.0.13
was resolved.
info : Package 'Microsoft.Azure.Cosmos' is compatible with all the
specified frameworks in project
'C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj'.
info : PackageReference for package 'Microsoft.Azure.Cosmos' version
'3.11.0' updated in file
'C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj'.
info : Committing restore...
info : Writing assets file to disk. Path:
C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\obj\project.assets.json
log : Restored
C:\Users\t-henzhu\Documents\AccessChangeMonitoring\AccessChangeMonitoring\AccessChangeMonitoring.csproj
(in 525 ms).
Is this a solution with a single project or do you have multiple projects and are using project references?
If this is the case, are you adding the package to all projects that will use it? On the SDK we have a sample Function App project that uses the V3 SDK (Microsoft.Azure.Cosmos) and works: https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage/AzureFunctions

The type or namespace name 'OpenIdConnect' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)

I have added a Microsoft.Owin.Security.OpenIdConnect.dll externally(tried both methods using Package Manager Console and using add reference ) to my ASP.NET MVC Application, but still get the same error.
The type or namespace name 'OpenIdConnect' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)
I have attached AccountController.cs, packages.config and references
Any help.
You can try with deleting Package folder from source directory (Location: .sln file), then try to resotre packages.
Steps to restore nuget packages:
Right click on solution file.
Select Nuget restore NuGet Package option
I found the solution from Microsoft site
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/0e92xd7b(v=vs.110)
Possible causes for this error include the following:
An assembly that contains the definition of a type was not referenced in the compilation; use /reference (Import Metadata) to specify the assembly
You passed a variable name to the typeof operator.
You tried to reference an assembly that is not part of your target .NET Framework profile. For more information, see Troubleshooting .NET Framework Targeting Errors.
In my case, the issue is that an assembly that is not part of my target .NET Framework profile.

Unable to move ASP.NET Identity model into another assembly

I have tried to follow the steps described in this link in order to pull out my identity class from the web application into its own class library.
http://www.umbraworks.net/bl0g/rebuildall/2013/10/22/Moving_ASP_NET_Identity_model_into_another_assembly
I do as follows:
Created a web form project and named it 3TierExample.
Created new class class library called 3TierExample.Model.
Installed Microsoft ASP.NET Identity EntityFramework package from NuGet into 3TierExample.Model
Moved identityModel.cs to the new class library (3TierExample.Model)
Added a reference to 3TierExample.Model in 3TierExample
Then for the identityModel.cs I use the following references:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;
using System.Web;
using System;
using _3TierExample.Models;
My namespace is as follows:
namespace _3TierExample.Models{…}
However when I finish I get the following errors:
I:..\3TierExample\3TierExample\Default.aspx: ASP.NET runtime error: Could not load file or assembly 'Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
I:...\3TierExample\3TierExample\Default.aspx 1 1 3TierExample
Metadata file 'I:..\3TierExample\3TierExample.Model\bin\Debug\3TierExample.Model.dll' could not be found
The type or namespace name 'HttpRequest' could not be found (are you missing a using directive or an assembly reference?) I:...\3TierExample
The type or namespace name 'HttpResponse' could not be found (are you missing a using directive or an assembly reference?) I:...\3TierExample
If I go to the web project I see that the reference to the newly created class library is there, so I don’t know how is it possible to get the first error (No 3). Then, the second error happens as a consequence, I think, of not finding the assembly reference. Why? The reference is there!?
Can anybody help?
Thank you in advance!!
There is an assembly conflicts.
When you create project, it could be having old version Asp.net Identity assemblies. You installed latest Asp.net Identity Packages in your class lib proj. If you want to separate Asp.net Identity Context from the main project, you don't need that framework in your web proj.
you can set No Authentication while creating your web project, which make sure there will not be conflicts when reference to Asp.net Identity Class Lib Project. You may require to copy IdentityModels.cs from sample Web Project in order to use in Class Lib Proj.

Google APIs/OAuth2 for .NET: dll integration/version issue

Ran the following in NuGet:
PM > Install-Package Google.Apis.Calendar.v3 -Pre
PM > Install-Package Google.Apis.Auth.Mvc -Pre
Per instructions at following locations
https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2
https://www.nuget.org/packages/Google.Apis.Calendar.v3/1.7.0.72-beta
https://www.nuget.org/packages/Google.Apis.Auth.Mvc
After adding these to the project and just a leaving a reference to Google.Apis.Calendar.v3.Data from a previous version that did not make use of the newly added references I get the following when attempting to build (I have tried cleaning first)
The type 'Google.Apis.Requests.IDirectResponseSchema' is defined in an assembly
that is not referenced. You must add a reference to assembly 'Google.Apis,
Version=1.7.0.24060, Culture=neutral, PublicKeyToken=null'.
Additional Facts
Google.Apis is definitely included.
The version number the Google.Apis dll reference added by NuGet is 1.7.0.34454
I checked in the registry (under .NET 4) and am running v4.5.xxxx
While solution explorer shows the assemblies under references they do not show up in the object explorer
When trying to reference namepaces/classes in these assemblies Intellisense is able to find them but when you build it says that it can not find the referenced namespace(s)
I verified that all google dlls are from the 1.7.x.xxxx (different build numbers)
We were originally referencing an older version of Google Calendar API but that reference was definitely updated to the most recent version
Exchanging the Google Calendar namespace reference with
using Google.Apis.Auth;
results in
The type or namespace name 'Auth' does not exist in the namespace 'Google.Apis'
(are you missing an assembly reference?)
This appears to have been a an issue with that particular version of the Google APIs, Google seems to have fixed it in the most recent version.

Categories