I'm following along with the tutorial at c-sharpcorner to add JWT authentication and running into an issue. I've re-done the entire tutorial and come up with the same issue in the same place.
After adding the extension class AddJWTTokenServicesExtensions in the MyApplication.Extensions namespace, and constructing the builder in Program.cs via var builder = WebApplication.CreateBuilder(args);, buider.Services is not recognizing the method AddJWTTokenServices
builder.Services.AddJWTTokenServices(builder.Configuration);
Error:
'IServiceCollection' does not contain a definition for 'AddJWTTokenServices' and no accessible extension method 'AddJWTTokenServices' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
Is the tutorial wrong in extending the class, or am I missing something obvious?
I have package references to EventFlow and EventFlow.AspNetCore. But can't register service:
services.AddEventFlow(ef =>
{
ef.AddDefaults(typeof(Startup).Assembly);
ef.AddAspNetCoreMetadataProviders();
});
Receiving an error:
CS1061 'IServiceCollection' does not contain a definition for 'AddEventFlow' and no accessible extension method 'AddEventFlow' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
Usings as follows:
using EventFlow.AspNetCore.Extensions;
using EventFlow.AspNetCore.Configuration;
using EventFlow;
using EventFlow.Extensions;
I had same problem. You need to add EventFlow.DependencyInjection package to your project. AddEventFlow method is defined there.
I started to try Unity GNU/Linux version. I got a project in my job that was written in Unity Editor version 5.6.6f2 for Windows. I could open the project in Unity Editor version 2019.3.8f1 after Unit Hub converting it for this newer version.
I'm getting a series of building errors now. And many of them are related to TextMesh Pro Asset in scripts generated during the building. Like
Library/PackageCache/com.unity.textmeshpro#2.0.1/Scripts/Runtime/TMP_FontAsset.cs(405,34): error CS0029: Cannot implicitly convert type 'UnityEngine.TextCore.FaceInfo' to 'TMPro.FaceInfo'
Library/PackageCache/com.unity.textmeshpro#2.0.1/Scripts/Runtime/TMP_FontAssetUtilities.cs(302,82): error CS1061: 'FaceInfo' does not contain a definition for 'pointSize' and no accessible extension method 'pointSize' accepting a first argument of type 'FaceInfo' could be found (are you missing a using directive or an assembly reference?)
Library/PackageCache/com.unity.textmeshpro#2.0.1/Scripts/Runtime/TMP_FontAssetUtilities.cs(344,82): error CS1061: 'FaceInfo' does not contain a definition for 'pointSize' and no accessible extension method 'pointSize' accepting a first argument of type 'FaceInfo' could be found (are you missing a using directive or an assembly reference?)
Library/PackageCache/com.unity.textmeshpro#2.0.1/Scripts/Runtime/TMP_FontAsset.cs(612,84): error CS1061: 'FaceInfo' does not contain a definition for 'tabWidth' and no accessible extension method 'tabWidth' accepting a first argument of type 'FaceInfo' could be found (are you missing a using directive or an assembly reference?)
Library/PackageCache/com.unity.textmeshpro#2.0.1/Scripts/Runtime/TMP_FontAsset.cs(649,28): error CS1061: 'FaceInfo' does not contain a definition for 'capLine' and no accessible extension method 'capLine' accepting a first argument of type 'FaceInfo' could be found (are you missing a using directive or an assembly reference?)
Library/PackageCache/com.unity.textmeshpro#2.0.1/Scripts/Runtime/TMP_FontAsset.cs(652,28): error CS1061: 'FaceInfo' does not contain a definition for 'capLine' and no accessible extension method 'capLine' accepting a first argument of type 'FaceInfo' could be found (are you missing a using directive or an assembly reference?)
There's a log file, Logs/Packages-Update.log, that I suppose is related to the updates made when converting the project from 5.6.6f2 version to 2019.3.8f1 version. The content of that file is
Packages were changed.
Update Mode: resetToDefaultDependencies
The following packages were added:
com.unity.collab-proxy#1.2.16
com.unity.ide.rider#1.1.4
com.unity.ide.vscode#1.1.4
com.unity.modules.ai#1.0.0
com.unity.modules.androidjni#1.0.0
com.unity.modules.animation#1.0.0
com.unity.modules.assetbundle#1.0.0
com.unity.modules.audio#1.0.0
com.unity.modules.cloth#1.0.0
com.unity.modules.director#1.0.0
com.unity.modules.imageconversion#1.0.0
com.unity.modules.imgui#1.0.0
com.unity.modules.jsonserialize#1.0.0
com.unity.modules.particlesystem#1.0.0
com.unity.modules.physics#1.0.0
com.unity.modules.physics2d#1.0.0
com.unity.modules.screencapture#1.0.0
com.unity.modules.terrain#1.0.0
com.unity.modules.terrainphysics#1.0.0
com.unity.modules.tilemap#1.0.0
com.unity.modules.ui#1.0.0
com.unity.modules.uielements#1.0.0
com.unity.modules.umbra#1.0.0
com.unity.modules.unityanalytics#1.0.0
com.unity.modules.unitywebrequest#1.0.0
com.unity.modules.unitywebrequestassetbundle#1.0.0
com.unity.modules.unitywebrequestaudio#1.0.0
com.unity.modules.unitywebrequesttexture#1.0.0
com.unity.modules.unitywebrequestwww#1.0.0
com.unity.modules.vehicles#1.0.0
com.unity.modules.video#1.0.0
com.unity.modules.vr#1.0.0
com.unity.modules.wind#1.0.0
com.unity.modules.xr#1.0.0
com.unity.test-framework#1.1.13
com.unity.textmeshpro#2.0.1
com.unity.timeline#1.2.14
com.unity.ugui#1.0.0
See the com.unity.textmeshpro#2.0.1 line in that.
I'm totally new to Unity and I don't use Windows. So I'm wondering if that have something related to C# scripting (like libraries that I have to install in Debian to properly compile a project), or if the errors are specific to TextMesh Pro asset etc.
If anyone have had this type of error or can give me tips to make Unity works in a Debian GNU/Linux environment...
Delete the old version of TextMesh Pro in the Asset folder
Reopen Project
Window -> TextMeshPro -> Import TMP essentials
Window -> TextMeshPro -> Project Files GUID Remapping Tool.
Scan & Save.
This will update the project and fix all missing TMP scripts.
I tried to create a rest api . when I try to change
services.AddDbContext<WebContext>(options =>
options.useSqlite(Configuration.GetConnectionString("WebContext")));
when I try to do this I get this error. I installed sqlite nuget.and also Microsoft.EntityFrameworkCore but I still got the problem
error CS1061: 'DbContextOptionsBuilder' does not contain a definition
for 'UseSqlite' and no extension method 'UseSqlite' accepting a first
argument of type 'DbContextOptionsBuilder' could be found (are you
missing a using directive or an assembly reference?
Try:
using Microsoft.EntityFrameworkCore;
...
services.AddDbContext<WebContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("WebContext")));
...
And you also need to install the Microsoft.EntityFrameworkCore.Sqlite nuget package.
I had to change my project from .NET Core 2.1 to .NET 4.7.1 and I fixed almost all errors except the following that are still eluding me
'IApplicationBuilder' does not contain a definition for 'UseHsts' and no extension method 'UseHsts' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
'IApplicationBuilder' does not contain a definition for 'UseAuthentication' and no extension method 'UseAuthentication' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
'IApplicationBuilder' does not contain a definition for 'UseCookiePolicy' and no extension method 'UseCookiePolicy' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
'IApplicationBuilder' does not contain a definition for 'UseHttpsRedirection' and no extension method 'UseHttpsRedirection' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
'IApplicationBuilder' does not contain a definition for 'UseSession' and no extension method 'UseSession' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
'IApplicationBuilder' does not contain a definition for 'UseStaticFiles' and no extension method 'UseStaticFiles' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
'IServiceCollection' does not contain a definition for 'AddAuthentication' and no extension method 'AddAuthentication' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
'IServiceCollection' does not contain a definition for 'AddSession' and no extension method 'AddSession' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
I am using Microsoft.AspNetCore.Builder and Microsoft.Extensions.DependencyInjection. What else do I need to use/install/add to get IApplicationBuilder and IServiceCollection to work?
In my WebApi.csproj file I changed the target framework from netcoreapp2.1 to net471.
Old:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
New:
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
Following Rik's answer, I searched for more packages and found I had to add all of the following NuGet Packages:
Microsoft.AspNetCore.Authentication
Microsoft.AspNetCore.Session
Microsoft.AspNetCore.HttpsPolicy
Microsoft.AspNetCore.CookiePolicy
Microsoft.AspNetCore.StaticFiles
After I did that I got no more error messages.
The 'AddSession' and 'UseAuthentication' errors can be fixed by using the following nuget packages.
Microsoft.AspNetCore.Session
Microsoft.AspNetCore.Authentication
First of all, switching to 4.7.1 isn't downgrading, it's moving to a different platform. Something you probably don't need to do, unless you want to reuse the code for a Winforms or WPF application.
The Microsoft.Extensions.* packages target .NET Standard 2.0, not just Core, so you can use them in the Full framework as well.
The packages and classes aren't tied to ASP.NET either, except hosting. I'm using them in console applications.
It also means that if your class libraries target .NET Standard 2.0 they can be used by both platforms without changing the target. Perhaps you could move most of the code to .NET Standard 2.0 libraries and leave just the configuration to runtime-specific projects
You don't strictly need hosting to use all the other extensions, although it does provide a convenient API similar to the ASP.NET Core code. You can write your own Startup class with Configure etc methods and call them explicitly. In the end, what you need is access to the IServiceCollection so you can get configured services and run them.
You can add a generic .NET host by using the Microsoft.Extensions.Hosting package. Apart from the common API it adds the ability to host long-running services to non-ASP.NET Core projects.
This blog post shows how you can use the Hosting package to create a console application that starts a long-running service, similar to a Windows service or daemon, eg :
public static async Task Main(string[] args)
{
var hostBuilder = new HostBuilder()
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<IBusControl>(serviceProvider =>
{
return MassTransit.Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host(new Uri("rabbitmq://localhost"), h =>
{
h.Username("guest");
h.Password("guest");
});
});
});
services.AddScoped<IHostedService, MassTransitHostedService>();
});
await hostBuilder.RunConsoleAsync();
}
The .NET Generic Host goes into more detail and shows more examples of logging, DI, configuration etc.
UPDATE
ASP.NET Core is not tied to .NET Core. You can use it in Full Framework projects as well, simply by changing the target runtime in the Project creationg dialog
Try to add "Microsoft.aspNetCore.App" to your *.csproj file ,this should solve the problem .
<ItemGroup>
<FrameworkReference Include="Microsoft.aspNetCore.App" />
</ItemGroup>
Please install Microsoft.AspNetCore.ResponseCaching from nuget package. It can fix your problem. After that described functionality will be available under .net framework.