更新到新包Microsoft.EntityFrameworkCore.SqlServer 1.1.2后,我尝试创建DBContext时出错:
System.IO.FileLoadException发生HResult = 0x80131040
Message =无法加载文件或程序集'Microsoft.Extensions.DependencyInjection.Abstractions,Version = 1.1.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(来自HRESULT的异常:0x80131040)Source = Microsoft.EntityFrameworkCore StackTrace:位于C:\ src\backend \中Services.Infrastructure.Data.SqlServerDbContext..ctor(DatabaseOptions databaseOptions)的Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions选项) Packages\Services.Infrastructure\Data\SqlServerDbContext.cs:位于C:\ src\backend\Modules\Translations\Translations.Api\Data\TranslationsDbContext.cs中Translations.Api.Data.TranslationsDbContext..ctor(DatabaseOptions databaseOptions)的第16行:第16行
我的基础DbContext
public class SqlServerDbContext : DbContext
{
private readonly DatabaseOptions _databaseOptions;
protected SqlServerDbContext(DatabaseOptions databaseOptions)
{
if (string.IsNullOrEmpty(databaseOptions.ConnectionString))
throw new Exception("Database connection string is missed.");
_databaseOptions = databaseOptions;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_databaseOptions.ConnectionString);
}
}
Run Code Online (Sandbox Code Playgroud)
我使用的数据库选项
public class DatabaseOptions
{
public string ConnectionString { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我创建上下文实例的地方
var dbOptions = new DatabaseOptions { ConnectionString …Run Code Online (Sandbox Code Playgroud) 我创建了几个.Net Standard 2.0库,通过控制台应用程序测试执行,以及几个测试 - 一切都很好.
然后我尝试将该特定版本下载到API Function项目中:

我正在使用Visual Studio版本15.7.0预览5.0.我已将Azure功能更新为4.7 ...因为控制台和测试项目是 - 并且这些工作.
这是一个太多的小时..所以我希望决议不是疯狂的事情.Ef Core 2.1.0-rc1-final也在混合中.使用Required,MaxLength,NotMapped的数据注释.
图形错误说:Microsoft.EntityFrameworkCore:无法加载文件或程序集'System.ComponentModel.Annotations,Version = 4.2.0.0
当我尝试在我的 c# .NET Framework 4.7.2 类库中打开表单时出现此错误。检查自动生成绑定重定向
调用堆栈是
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) …Run Code Online (Sandbox Code Playgroud) 我有一个包含库和2个应用程序的解决方案.这些应用程序代表相同的程序,其中一个程序是通过UAP10定位到Windows App Store,另一个是使用.Net Framework 4.6.1定位到Microsoft Windows PC.我正在使用Visual Studio 2017.
UWP版本编译并运行良好.
最初,.Net Framework 4.6.1编译并运行.但是,当我从System.IO调用File.Open时,收到以下错误消息:
System.IO.FileNotFoundException:'无法加载文件或程序集'System.IO.FileSystem,Version = 4.0.1.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.'
File.Run的代码块在库代码(.Net Standard 1.4)中.我不确定是什么导致了这个问题.我认为我可以在引用.Net Framework 4.6.1的应用程序中使用.Net Standard 1.4库.
作为一种解决方法,我尝试在.Net Framework应用程序中安装System.IO的Nuget包.System.IO版本4.0.1.0甚至不是一个选项.有一个版本4.0.10,但安装此Nuget包时它不起作用.
那么,如何在.Net Framework 4.6.1应用程序中正确引用System.IO操作,该应用程序引用.Net Standard 1.4库中的System.IO代码?
请注意:这是不是一个重复无法加载文件或程序集“System.ComponentModel.Annotations,版本= 4.1.0.0。与链接的问题不同,此问题仅在发布应用程序之后发生。正如您将在下面看到的那样,我尝试了该帖子中提出的所有解决方案,但均未成功。
在WPF .Net Framework 4.6.1项目中,该问题引用了.Net Standard 2.0库,该库本身引用了System.ComponentModel.Annotations NuGet包。
该问题在以下项目中再现:https : //github.com/kaitlynbrown/DataAnnotationsError
重现该错误:
您将看到以下错误:
我已经尝试了多种方法来解决此问题,包括:
在WPF项目的.csproj中添加以下行:
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
Run Code Online (Sandbox Code Playgroud)
在App.config中添加以下绑定重定向:
<runtime>
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
</dependentAssembly>
</runtime>
Run Code Online (Sandbox Code Playgroud)
在WPF项目中添加对System.ComponentModel.Annotations NuGet包的引用
这些都不起作用。
请注意:问题不在 Visual Studio中构建和运行。我能够做到这一点而没有错误。尝试发布应用程序并随后运行发布的应用程序时,会发生此问题。
.net c# .net-assembly assembly-binding-redirect .net-standard
使用ServiceStack.OrmLite.Core包 (5.4.1) 并尝试通过执行以下操作获取ModelDefinition( ServiceStack.OrmLite.ModelDefinition)时出现运行时错误:
var model = ModelDefinition<T>.Definition;
Run Code Online (Sandbox Code Playgroud)
错误如下:
System.IO.FileLoadException: 'Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
Run Code Online (Sandbox Code Playgroud)
我试图安装 nuget System.ComponentModel.Annotations(4.5.0.0,因为 4.2.0.0 不可用)无济于事。我还尝试了遇到 System.IO.FileLoadException 时建议的各种修复,但没有任何效果。
该项目是一个 .Net Framework 4.7.1 项目,但 .Net Standard 项目包含在解决方案中,因此我需要运行 ServiceStack.OrmLite 的 .Core 版本。
我已经在两个工作区(两台单独的机器)上尝试过这个,(1) 如上所述,(2) 解决方案中没有 .Net Standard 项目。在 (2) 机器上,它在运行非核心版本的 时工作ServiceStack.OrmLite,但发生切换到ServiceStack.OrmLite.Core …
我有一个参考的netstandard 2.0项目System.ComponentModel.Annotations。它可以在本地计算机上很好地构建,但是当我尝试使用Azure DevOps管道构建它时,出现以下错误:
...警告MSB3245:无法解析此引用。无法找到程序集“ System.ComponentModel.Annotations”。检查以确保程序集在磁盘上。如果您的代码需要此引用,则可能会出现编译错误。[/home/vsts/work/1/s/src/MyProj/MyProj.csproj]
... MyProj / MyClass.cs(2,29):错误CS0234:类型或名称空间名称'DataAnnotations'在名称空间'System.ComponentModel'中不存在(您是否缺少程序集引用?)[/ home / vsts /work/1/s/src/MyProj/MyProj.csproj]
该错误是不言自明的,并且我理解该错误的含义,但问题是我应该如何解决此问题,以满足Azure DevOps的构建?
azure-devops azure-pipelines .net-standard .net-standard-2.0
c# ×6
.net ×4
.net-core ×2
.net-4.6.1 ×1
azure-devops ×1
datagridview ×1
servicestack ×1
winforms ×1