I'm following this tutorial on adding JWT authentication into my dotnet core web api. I've added the [AllowAnonymous] attribute a method in my controller, however I'm getting an error stating the type or namespace cannot be found.
The type or namespace name 'AllowAnonymous' could not be found (are you missing a using directive or an assembly reference?) (CS0246) [GitWrap]
I've seen this answer to the same question, and after following the suggestions (to add a reference to System.Web.Http), I still have the same error.
Note, I'm working with VSCode (which I'm quite unfamiliar with), and added the package with the following command:
dotnet add package System.Web.Http
The lined posted also states to add a reference to System.We.Mvc, which I've done using the dotnet add package command. And finally, I've restored the packages with dotnet restore, but I still have the same error.
Can anyone please point out how properly add a reference to the required package in dotnet core, so I can use the AllowAnonymous attribute?
Related
Today, I upgraded my projects to netcoreapp 2.1 to 2.2.
After that, my projects using Microsoft.AspNetCore.Identity give me an error:
error CS0234: The name or namespace name 'Identity' does not exist in the 'Microsoft.AspNetCore' namespace (are you missing an assembly reference?)
If I add the Microsoft.AspNetCore.Identity nuget package in project reference, I don't have any error with using directive, but I have always error on cannot found IdentityUser
I also cleaned nuget cache on my machine
My code is here: https://github.com/SOFTINUX/Base
(If, you would try to reproduce, you need to restore npm packages in Barebone project before build)
So, in netcoreapp 2.2, Microsoft.AspNetCore.Identity is not found. With netcoreapp2.1, I have no problems.
I want to use Identity into my app with netcore2.2, but I not found any informations about changes on it and I tested with example app in netcoreapp2.2 and I have no problem with it.
I supppose, the problem come from my project, but I dont see nothing
Thanks.
I've just cloned it and tried building it.
The error shows, that the namespace Microsoft.AspNetCore.Identity is missing in the SoftinuxBase.Security.Data.Entities project and that the compiler cannot find a reference for IdentityUser<T> and IdentityRole<T> both of which reside inside the Microsoft.AspNetCore.Identity.EntityFrameworkCore package.
So to resolve your error add the this package to your entities project, either through project reference or package manager console:
install-package Microsoft.AspNetCore.Identity -ProjectName SoftinuxBase.Security.Data.Entities
install-package Microsoft.AspNetCore.Identity.EntityFrameworkCore -ProjectName SoftinuxBase.Security.Data.Entities
The EntityFrameworkCore package has a dependency on the base Identity package and should pull that in implicitly, I've just added in the install-package command for clarity. In theory you should get away with just pulling in The EF package.
After getting rid of all the other small issues like the missing Microsoft.AspNetCore.StaticFiles package, I can compile the solution and get greeted by the following browser window:
So I suppose that this resolves your issue.
I am trying to create some ASP.net 5 MVC Web Application using VS 2015 CE.
I am always getting error with DNX Core and DNX 4.5 as not being referenced to the project.
I tried changing the project.json file by removing entries in
"frameworks" section and keeping only one at a time from both "dnx451"
and "dnxcore50", still no luck.
I ended up with the large list of compile time error primarily because of the following error.
CS1061 'ApplicationDbContext' does not contain a definition for 'Database' and no extension method 'Database' accepting a first argument of type 'ApplicationDbContext' could be found (are you missing a using directive or an assembly reference?) DemoApp.DNX 4.5.1
and on the same lines
CS1061 'ApplicationDbContext' does not contain a definition for 'Database' and no extension method 'Database' accepting a first argument of type 'ApplicationDbContext' could be found (are you missing a using directive or an assembly reference?) DemoApp.DNX Core 5.0
Tried using 'Restore Packages' command as well but nothing happens.
I dropped the project and re-created, however same things happened again.
As far as I know it worked before and now I don't know what went wrong all of the sudden.
I resolved problem by..
Deleting the project.lock.json file (figured out this was not allowing to upgrade and resolve the References)
Running a DNVM upgrade command from command prompt.
We are using EPPlus to generate Excel documents. Code builds successful in my local system but it is failing when we build through TeamCity and getting below error -
error CS0246: The type or namespace name 'OfficeOpenXml' could not be found (are you missing a using directive or an assembly reference?)
I have tried Google to find the solution but all in vain. My Project target framework is 4.5.2 and I have also added System.Core and WindowsBase. I have also added namespace "using OfficeOpenXml"
EPPlus is added through Nuget Package.
If you have any packages installed using NuGet, then you need to add a NuGet Installer build step in your build configuration before the actual build command, using the solution file which references the NuGet packages you need. This step is what causes TeamCity to download any NuGet packages that are required that it doesn't have installed.
I solved it by removing and add EPPlus reference manually.
I encounter this kind of error when I debug a project
I already have EntityFramework.dll, System.Core.dll, System.Data.Entity but still Core is not referenced.
Can someone help me?
I'm having error in this Line
using System.Data.Entity.Core.Objects;
This is the error:
The type or namespace name 'Core' does not exist in the namespace 'System.Data.Entity' (are you missing an assembly reference?)
Enrique, I had this problem crop up when I started opening a project on my desktop that I had normally been opening on my VM. Masoud's answer is not helpful... I don't think he read your original post.
What I did to clear this compile error up was to open NuGet package manager and install the update that was available for EntityFramework. I had version 6.1.1 installed in the project and I upgraded to 6.1.3. I should not have had the error to start with, but upgrading the version appeared to jiggle whatever it was loose because I started compiling fine after that.
Sometimes, when you add references from other sources than nuget manager (example: Local source) you need to verify the HintPath of that reference before moving your application in another environment
I'm using creating a .Net 4.0 application to post stuff to Twitter using the Tweetinvi API. I can't use packages, so I've downloaded the dll's and added them to my project:
Yet my includes are showing errors:
My error console shows:
Error 423 The type or namespace name 'Core' does not exist in the
namespace 'Tweetinvi' (are you missing an assembly
reference?) {...file...}.cs 10 17 ApiProviders
Can anyone tell me why this happens and how I could fix this?
Tweetinvi requires the Bcl.Async package. You need to add that too.
Check all the dependencies and make shure all are installed.
BUT as already said I highly recommend using NuGet for this. If you are not allowed to use the "public feed" you can download the packages and put them in a local folder and add this folder as a new feed in Visual Studio.
Have you tried downloading the project from the download page?
https://tweetinvi.codeplex.com/downloads/get/852208