c# - “Microsoft.EntityFrameworkCore.Query.QueryableMethods”的类型初始化程序引发异常
问题描述
我有一个功能应用程序,当我使用azure-functions-core-tools@4.0.3780
start
命令运行它时会引发以下错误。
func start
System.Private.CoreLib: Exception while executing function: Test.
Microsoft.EntityFrameworkCore: The type initializer for
'Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor'
threw an exception. Microsoft.EntityFrameworkCore:
The type initializer for
'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
System.Linq: Sequence contains more than one matching element.
入口点
private readonly IRepository _repository;
[FunctionName("Test")]
public async Task TestAsync(
[ServiceBusTrigger(
"%topic%",
"%subscription%",
Connection = "connectionString")]
Message message)
{
var result = await _repository.ToListAsync();
}
从 Visual Studio 启动函数应用程序时,它工作正常。
Microsoft.EntityFrameworkCore
我想我可以通过在函数应用程序 csproj 中直接引用来摆脱它。
有任何想法吗?
谢谢
函数应用程序.csproj
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus"
Version="4.3.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FirstLib\FirstLib.csproj" />
</ItemGroup>
FirstLib.csproj
<ItemGroup>
<ProjectReference Include="..\SecondLib\SecondLib.csproj" />
</ItemGroup>
SecondLib.csproj
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="3.1.8" />
</ItemGroup>
视觉工作室版本
Microsoft Visual Studio Professional 2019
Version 16.10.4
解决方案
当我升级Microsoft.EntityFrameworkCore
到依赖时问题就消失5.0.0
了。SecondLib
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="5.0.0" />
</ItemGroup>
没有被TargetFramework
触动
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
推荐阅读
- asp.net-mvc - 在会话超时 ASP MVC 6 上将任何页面重定向到登录屏幕
- opencv - 从 Kinect2 颜色流中提取 3 个通道
- wpf - 如何使用转换器设置组合框项目的文本?
- android - Hashmap 未附加到适配器
- forms - 在 Symfony 4 上验证用户的正确方法
- angular - Refreshin 角度构建在 Apache 服务器上显示 404 Not Found 错误
- uml - 在所有流都到达合并节点之前,UML 合并节点是否不会退出?
- database - EclipseLink:PostgreSQL 返回空列表作为 text[] 的默认值?
- c# - 创建文件夹结构的副本
- azure-devops - 处理多个项目和一个团队