【发布时间】:2022-01-09 22:06:17
【问题描述】:
我正在开发一个持久的 Azure 功能。我正在使用 .NET Core 3.1。它是一个 HTTP 触发的函数。当我从 Visual Studio 调试它然后通过调用端点来触发它时,一切正常。
在同一台机器上,我安装了 Azure Functions Core Tools (4.0.3971)。我运行存储模拟器:
C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe start
然后转到我的函数所在的目录并输入:
func start
一切都和以前一样,所以我通过向端点发出请求来触发我的函数。它开始工作,但随后抛出以下错误:
[2021-12-03T14:25:51.081Z] Executed 'MyFunction_Process' (Failed, Id=f709e4c0-f74e-4303-a68b-6d5d55f0f7e5, Duration=2182ms)
[2021-12-03T14:25:51.086Z] System.Private.CoreLib: Exception while executing function: MyFunctionIntegration_Process. Microsoft.EntityFrameworkCore: The type initializer for 'Microsoft.EntityFrameworkCore.EnumerableMethods' threw an exception. System.Linq: Sequence contains more than one matching element.
[2021-12-03T14:25:51.101Z] myfunctionsingleinstance: Function 'MyFunction_Process (Activity)' failed with an error. Reason: System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.EnumerableMethods' threw an exception.
[2021-12-03T14:25:51.106Z] ---> System.InvalidOperationException: Sequence contains more than one matching element
[2021-12-03T14:25:51.110Z] at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
[2021-12-03T14:25:51.112Z] at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
[2021-12-03T14:25:51.113Z] at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
[2021-12-03T14:25:51.115Z] at Microsoft.EntityFrameworkCore.EnumerableMethods..cctor()
[2021-12-03T14:25:51.116Z] --- End of inner exception stack trace ---
[2021-12-03T14:25:51.117Z] at Microsoft.EntityFrameworkCore.EnumerableMethods.get_AnyWithPredicate()
[2021-12-03T14:25:51.119Z] at Microsoft.EntityFrameworkCore.Query.Internal.AllAnyToContainsRewritingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
[2021-12-03T14:25:51.121Z] at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
[2021-12-03T14:25:51.124Z] at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
[2021-12-03T14:25:51.126Z] at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
[2021-12-03T14:25:51.128Z] at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
[2021-12-03T14:25:51.129Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
[2021-12-03T14:25:51.131Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
[2021-12-03T14:25:51.133Z] at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
[2021-12-03T14:25:51.134Z] at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
[2021-12-03T14:25:51.136Z] at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
[2021-12-03T14:25:51.140Z] at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
[2021-12-03T14:25:51.141Z] at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
[2021-12-03T14:25:51.143Z] at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.IncludableQueryable`2.GetEnumerator()
[2021-12-03T14:25:51.144Z] at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
[2021-12-03T14:25:51.146Z] at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)
[2021-12-03T14:25:51.148Z] at Logistics.Infrastructure.MyFunctionIntegration.Integration.GetDbRows(ILogger log) in C:\Users\Michal\source\repos\Logistics\src\backend\src\infrastructure\Logistics.Infrastructure.MyFunctionIntegration\Integration.cs:line 103
...
第 103 行是:
var dbEntities = _dbContext.Carriers.IgnoreQueryFilters().Include(c => c.CarrierGitd.Address).ToDictionary(c => c.CarrierGitd?.LicenseNumber);
所以当我尝试从数据库中获取数据时会发生这种情况。但它工作正常,当我在 VS 中调试时。数据库是一样的。问题在哪里?
【问题讨论】:
标签: .net-core azure-functions azure-functions-core-tools azure-storage-emulator