'Microsoft.EntityFrameworkCore.Query.QueryableMethods'的类型初始值设定项引发异常



当我用azure-functions-core-tools@4.0.3780start命令运行它时,我有一个函数应用程序抛出以下错误。

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启动函数应用程序时工作正常

我想我可以通过在函数应用程序csproj中直接引用Microsoft.EntityFrameworkCore来摆脱它。

任何想法?

感谢FunctionApp.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="..FirstLibFirstLib.csproj" />
</ItemGroup>

FirstLib.csproj

<ItemGroup>
<ProjectReference Include="..SecondLibSecondLib.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>

Visual Studio版本

Microsoft Visual Studio Professional 2019
Version 16.10.4

当我在SecondLib依赖中将Microsoft.EntityFrameworkCore升级到5.0.0时,问题就消失了。

<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>

相关内容

  • 没有找到相关文章

最新更新