serilog-settings-configuration: AssemblyFinder throw Exception in .Net5.0(RC2) SingleFile
Unhandled exception. System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
at System.Reflection.RuntimeAssembly.get_CodeBase()
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.GetNormalizedCodeBasePath(Assembly assembly)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.GetDepsJsonPath(Assembly assembly)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.LoadAssemblyContext(Assembly assembly, IDependencyContextReader reader)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.Load(Assembly assembly)
at Microsoft.Extensions.DependencyModel.DependencyContext.Load(Assembly assembly)
at Microsoft.Extensions.DependencyModel.DependencyContext.LoadDefault()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at System.Lazy1.get_Value()
at Microsoft.Extensions.DependencyModel.DependencyContext.get_Default()
at Serilog.Settings.Configuration.Assemblies.AssemblyFinder.Auto()
at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, String sectionName, DependencyContext dependencyContext)
at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, DependencyContext dependencyContext)
at HostApp.Program.<>c.<CreateHostBuilder>b__1_2(WebHostBuilderContext hosting, LoggerConfiguration logger)
at Serilog.SerilogWebHostBuilderExtensions.<>c__DisplayClass1_0.<UseSerilog>b__0(WebHostBuilderContext context, IServiceCollection collection)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass11_0.<ConfigureServices>b__0(HostBuilderContext context, IServiceCollection builder)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at HostApp.Program.Main(String[] args)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (9 by maintainers)
Another workaround is to set
IncludeAllContentForSelfExtracttotruewhen publishing. Setting this property to true changes the.NET 5.0system of single-file apps to be backward compatible with the.NET Core 3.xsystem (as described here).I have tested this with version
3.2.0-dev-00264ofSerilog.Settings.Configurationand it works; version3.1.0will not work.Some additional info on the workaround can be found here - https://github.com/dotnet/runtime/issues/44511#issuecomment-725253197 Related issue - https://github.com/dotnet/runtime/issues/42265
Seems working fine and I feel dumb
@murugaratham just remove this line
var functionDependencyContext = DependencyContext.Load(typeof(Startup).Assembly);