AssemblyFinder throw Exception in .Net5.0(RC2) SingleFile
See original GitHub issueUnhandled 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.Lazy
1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at System.Lazy
1.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)
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (9 by maintainers)
Another workaround is to set
IncludeAllContentForSelfExtract
totrue
when publishing. Setting this property to true changes the.NET 5.0
system of single-file apps to be backward compatible with the.NET Core 3.x
system (as described here).I have tested this with version
3.2.0-dev-00264
ofSerilog.Settings.Configuration
and it works; version3.1.0
will 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