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.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
与程序集文件位置相关的多个API以单文件发布格式被调用时,其行为会发生变化
因为单文件程序集都合并为一个了,所以有一些路径相关的API均无法支持
https://github.com/dotnet/runtime/pull/42306
解决方法
Avoid dependencies on the file location of assemblies when publishing as a single file.
作为单个文件发布时,避免依赖程序集的文件位置。
.net 5 单文件模式发布异常 CodeBase is not supported on assemblies loaded from a single-file bundle
原文:https://www.cnblogs.com/WNpursue/p/14717646.html