Why do I get "Cannot resolve symbol 'CreatePerOwinContext'"? - c#

I have a self hosted owin Web Api and I'm trying to use a single instance of my EF Context per Owin Request. Here is my config code for the startup class.
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext(A3Context.Create);
}
This won't build because I get the following error.
Error
5 'Owin.IAppBuilder' does not contain a definition for
'CreatePerOwinContext' and no extension method 'CreatePerOwinContext'
accepting a first argument of type 'Owin.IAppBuilder' could be found
(are you missing a using directive or an assembly reference?)
I'm I missing a reference that I'm not aware of?

CreatePerOwinContext is an extension method in the Microsoft.AspNet.Identity.Owin NuGet package.
To resolve, open package manager console for your project and install with the following command:
Install-Package Microsoft.AspNet.Identity.Owin
Ensure you are referencing the namespace containing the extension method:
using Owin;

Related

DBContextBuilder doesnot contain a definition for UseSqlServer in .NET 6

I'm trying to implement microservices in .NET core framework (version 6.0) and facing this particular issue while adding the services of DBContext in the Program.CS file.
statement I'm using :
builder.Services.AddDbContext<ProductContext>(options=>options.UseSqlServer(builder.Configuration.GetConnectionString("ProductDB")));
Error CS1061 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no accessible extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?) Micro D:\NET_Micro\Micro\Micro\Program.cs 7 Active
These Errors occur usually when you are not including certain packages in your code.
Try downloading the following NuGet packages by running below mentioned code in your visual studio's package manager console :
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Design
and include them in your startup.cs/program.cs :
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;
using Microsoft.EntityFrameworkCore.Design;
Try to install the Microsoft.EntityFrameworkCore.SqlServer NuGet Package.
Then, import the namespace with
using Microsoft.EntityFrameworkCore;
Seems there was a bug in VisualStudio 2022, had to restart and reinstall below packages to get it working:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;

AutoMapper .net 6.0 not in service

I downloaded automapper to a separate class library. I want to use this automapper in web api. I want to add automapper to services in program.cs, but it gives the following error.
Severity Code Description Project File Line Hide Status Error CS1061
'IServiceCollection' does not contain a definition of 'AddAutoMapper'
and no accessible extension method 'AddAutoMapper' was found that
accepts a first argument of type 'IServiceCollection' (could be
missing a using directive or assembly reference?) WebApi
C:\Users\batu_\ Desktop\TaskProject\Backend\WebApi\Program.cs 8
Enabled
enter image description here
I downloaded automapper from nuget to map class library
Can't find AddAutoMapper in program.cs
builder.Services.AddAutoMapper(typeof(MappingProfile));
You need to add a reference to: AutoMapper.Extensions.Microsoft.DependencyInjection

How to include Windows.Security.Credentials.UI namespace into C# project

My goal is to work with Windows.Security.Credentials.UI namespace to create a program that authenticates users through their Windows pin, similar to Opera Password Manager:
The only problem is that I cannot figure out how to include the namespace into my program.
I've tried including it as so:
using Windows.Security.Credentials.UI;
However, that returned an error:
The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
I have also tried to include the namespace as a reference but I cannot locate it inside the References menu.
What is the correct method to install the Windows.Security.Credentials.UI namespace in C# .NET 4.7.2 Console Application?
When using the .NET Framework, you must include the Microsoft.Windows.SDK.Contracts nuget package and then you will have access to (some) WinRT APIs.
Here is a sample C# Console Application:
class Program
{
static async Task Main()
{
await Windows.Security.Credentials.UI.UserConsentVerifier.RequestVerificationAsync("hello world").AsTask();
}
}
It works because this API is marked as DualApiPartition.
Also make sure you're using PackagesReference format for nuget packages and not the packages.config configuration.

AllowAnonymous could not be found

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?

The type or namespace name 'Configuration' does not exist in the namespace 'WebApiContrib.Formatting.Html'

I'm getting this error with my Visual Studio 2012, Console App (it is a self-hosted webApi OWIN project)....
The type or namespace name 'Configuration' does not exist in the namespace
'WebApiContrib.Formatting.Html' (are you missing an assembly reference?)
The error is coming from this line ...
using WebApiContrib.Formatting.Html.Configuration;
I'm also getting a similar error for ...
using WebApiContrib.Formatting.Html.Formatters;
using WebApiContrib.Formatting.Html.Locators
In the project references I can see...
WebApiContrib.Formatting.Html
Any ideas how I can fix it please?
According to the documentation the HtmlMediaTypeViewFormatter type, and probably others, are found in WebApiContrib.Formatting.Html.Formatting. You don't need the Configuration namespace.
Check if you have installed all necessary packages and the latest version by using the NuGet package manager:
PM> Install-Package WebApiContrib.Formatting.Html

Categories

Resources