我有一个.NET Standard 1.4类库,它引用了System.ComponentModel.Annotations(4.3.0)NuGet包.
然后,我将从.NET Framework 4.6.2测试项目中引用此类库.它构建良好,但在运行时我收到以下错误:
发生System.IO.FileLoadException HResult = 0x80131040
消息= 无法加载文件或程序集'System.ComponentModel.Annotations,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
我尝试从net462项目添加对System.ComponentModel.Annotations(4.3.0)NuGet包的引用,但这没有任何区别.
我尝试从net462项目中添加对.NET标准库的引用,但仍然没有运气.
我在这里错过了什么吗?这是一个已知的错误,如果有的话有解决方法吗?
任何帮助深表感谢!
尝试从 Azure Function 中的 IConfiguration 设置 Serilog 时,出现以下错误。
无法加载文件或程序集“Microsoft.Extensions.DependencyModel,Version=3.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。该系统找不到指定的文件。
该错误是在运行时抛出的:
var loggerConfiguration = new LoggerConfiguration().ReadFrom.Configuration(Configuration);
我的启动类如下所示:
public class Startup : FunctionsStartup
{
public IConfiguration Configuration { get; set; }
public override void Configure(IFunctionsHostBuilder builder)
{
Configuration = builder.GetContext().Configuration;
(...)
var loggerConfiguration = new LoggerConfiguration().ReadFrom.Configuration(Configuration);
var logger = loggerConfiguration.CreateLogger();
builder.Services.AddLogging(lb => lb.AddSerilog(logger));
}
}
Run Code Online (Sandbox Code Playgroud)
我可以在项目的依赖项中看到 Microsoft.Extensions.DependencyModel(3.0.0) 依赖项,作为 Serilog.Settings.Configuration(3.3.0) 的子依赖项。
我可以对 Serilog 配置进行硬编码,并使其与 MSSqlServer 接收器一起工作,但重点是通过简单的设置更改来配置此功能。
我正在使用 .net6 和 azure 函数 v4。
编辑:添加 .csproj 示例
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference …Run Code Online (Sandbox Code Playgroud) 在我的 azure 函数应用项目中,我收到一个程序集未找到运行时错误 Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0。但是,该程序集包含在我从 NuGet 安装的多个包中。
Visual Studio:2019 目标框架:netcoreapp3.1 Azure Functions 版本:v3
包含 Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0) 的已安装包:
错误: 启动操作期间发生主机错误...无法加载文件或程序集“Microsoft.Extensions.DependencyInjection.Abstractions,Version=5.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。该系统找不到指定的文件。
无效的修复尝试: 从 NuGet 安装了 Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0),但错误仍然存在。
在类似的问题Microsoft.Extensions #2931和StackOverflow question 之后,我在项目文件中添加了以下内容。
<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我也跟着一篇文章的建议。安装 Microsoft.Azure.Functions.Extensions 后,错误仍然存在。
我还遵循了另一个建议,并将以下内容添加到我的项目文件中。但是,错误仍然存在。
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions"
publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="5.0.0.0"
newVersion="5.0.0" /> </dependentAssembly> </assemblyBinding> </runtime>
Run Code Online (Sandbox Code Playgroud)
我尝试了ASP.NET Core 公告的问题#401 中建议的解决方法:引用未能在我的应用程序中显式加载的程序集的包。但是,错误仍然存在。
使用 ILSpy,我发现我从 NuGet 安装的 Microsoft.Azure.Functions.Extensions …
[最近的笔记]
如果不是 com-visible 方面,这个问题将是这个问题的副本关于 assembly binding。我已经挣扎了好几天,因为我没有意识到我需要改变我的单元测试项目以及 com 可见项目。如果你不想通读我意识到这一点的挣扎,请跳到最后一次更新。
[前言]
我担心这可能是尝试通过 COM Visible Framework 4.7.2 库从 VB6 访问 dotnet 标准 2.0 库的桥梁,但想尝试一下。
你好世界确实有效。(即调用一个返回字符串的简单函数)
但是,当我尝试通过 IDE 或作为 .EXE 运行 VB6 程序时出现此错误。
该错误消息表明该问题发生在 c# dotnet standard2.0 库的代码中。
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions,
Version=3.1.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60' or one of its dependencies.
The system cannot find the file specified.
File name: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>g__BuildServiceProvider|3()
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired) …Run Code Online (Sandbox Code Playgroud) 每当我想通过 NetFramework 4.8 项目上的 NuGet 将 EFCore 引用更新为版本 3 时,我都会收到此错误。
我确认我的机器上安装了 netcore 3.0 SDK。
Could not install package 'Microsoft.EntityFrameworkCore 3.0.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.
Run Code Online (Sandbox Code Playgroud) 我成功地从框架 4.7.2 测试项目中调用了 .net 标准 2.0 库。

如果我使用我的 .net 标准 2.0 dll (SBD.Standard) 并创建一个引用它的新 winforms 项目,那么我会被要求添加
Microsoft.EntityFrameworkCore,
then Microsoft.EntityFrameworkCore.SqlServer,
then Microsoft.Data.SqlClient
Run Code Online (Sandbox Code Playgroud)
然后我的项目成功运行。(虽然如果自动添加额外的包会很理想)
但是,如果我尝试通过使用 Azure DevOps 构建的 Nuget 包分发我的库,则会出现问题。
但是,当我通过 Nuget(使用 Azure DevOps 创建 Nuget)分发标准库并将其包含在新项目中时,出现错误。
调用堆栈是
System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.0.19269.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' or one of its dependencies. The system cannot find the file specified.
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState …Run Code Online (Sandbox Code Playgroud) nuget entity-framework-core azure-devops .net-standard .net-4.7.2
.net ×2
c# ×2
.net-4.7.2 ×1
.net-6.0 ×1
.net-core ×1
azure-devops ×1
com ×1
nuget ×1
serilog ×1
vb6 ×1