Closed xiongdashan closed 4 years ago
I'll try to reproduce it
It works if you change Program.cs from:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
to:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
It looks like the IWebHostBuilder
doesn't register the IApplicationBuilder
Okay. So this framework can't use in .net framework 4.8?
Kledex is based on .NET Standard 2.1 which is not currently supported in .NET Framework 4.8. Please check the compatibility for .NET Standard here: https://docs.microsoft.com/en-us/dotnet/standard/net-standard.
How can i use Autofac directly, without ServiceCollection;
Like
var servcies = new ServiceCollection();
servcies.AddKledex();
to
var builder = new ContainerBuilder()
builder.Register......
Severity Code Description Project File Line Suppression State
Error Could not install package 'Kledex 2.5.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
You should be able to do something like this:
servcies.AddKledex();
var builder = new ContainerBuilder();
builder.Populate(services);
// add other stuff to Autofac
Yes, I using builder.Populate... But my project is Mvc Web Api using .net framewrok 4.8.
As I have already mentioned .NET Standard 2.1 is not supported yet in .NET Framework 4.8.
Okay, thanks for your replay。
Closing as it is established that it's a compatibility issue.
Do we have a permanent fix for this without changing the Program.cs ? not below one :
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
I don't think so, sorry.
.net core 3.1 mvc api
add Kledex in startup.cs
exception:
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Builder.IApplicationBuilder' while attempting to activate 'Kledex.Extensions.KledexAppBuilder'.