3

我使用带有 Azure Functions V1 的 Azure Functions 工具创建了一个全新的项目:

在此处输入图像描述

然后我按 F5 并得到黄色闪电,然后出现错误消息:

" An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = WebScriptHostManager (DelegateActivator), Services = [Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> The type initializer for 'Microsoft.Azure.WebJobs.Script.Utility' threw an exception. (See inner exception for details.)"

在此处输入图像描述

我的设置是:

视觉工作室 2017 - 15.6.7

Azure SDK 功能 1.0.12

Azure 函数 V1

Azure Web 作业工具 - 15.0.40215.0

Azure CLI 1.0.12

这是我的 VS 控制台的输出:

func.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\func.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Autofac.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.IO.Abstractions.dll'. Cannot find or open the PDB file.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Newtonsoft.Json\9.0.0.0__30ad4fe6b2a6aeed\Newtonsoft.Json.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\ARMClient.Authentication.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\ARMClient.Library.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Colors.Net.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.Azure.WebJobs.Script.dll'. Cannot find or open the PDB file.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.Extensions.Logging.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.Azure.WebJobs.Host.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.Azure.WebJobs.Script.WebHost.dll'. Cannot find or open the PDB file.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\FluentCommandLineParser.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.Web.Http.SelfHost.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.Web.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.Net.Http.Formatting.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.Web.Http.Cors.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Ignite.SharpNetSH.dll'. Cannot find or open the PDB file.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Autofac.Integration.WebApi.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Generic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Azure.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Pusher.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Stripe.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Trello.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.DynamicsCRM.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.MailChimp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Slack.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Bitbucket.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Dropbox.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.WordPress.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.GitHub.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.Salesforce.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.Azure.AppService.Proxy.Common.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.Azure.WebJobs.Extensions.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Receivers.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.Azure.WebJobs.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.WindowsAzure.Storage.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\Microsoft.AspNet.WebHooks.Common.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.Reactive.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.Reactive.Interfaces.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'func.exe' (CLR v4.0.30319: func.exe): Loaded 'C:\Users\Stanley\AppData\Local\Azure.Functions.Cli\1.0.12\System.Reactive.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[15204] func.exe' has exited with code -1073741510 (0xc000013a).

我尝试过:卸载并重新安装 Azure Dev 工作负载以及 CLI 工具我没有尝试卸载/重新安装 VS,因为这至少需要半天时间。

我怀疑问题出在 Azure CLI

我对 Azure Functions + VS 感到非常沮丧。让他的东西工作起来绝对是一场噩梦!

4

3 回答 3

2

问题解决了 !

感谢 Jerry Liu,我设法调试了 Azure Function Core Tools 的源代码。

错误消息原来是 Newtonsoft 相关的:

"Could not load type 'Newtonsoft.Json.Converters.ExpandoObjectConverter' from assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'."

所以我只是运行 nuget 将源代码更新到最新版本的 Newtonsoft。然后我将重建的源代码复制到:

C:\Users[MyUserName]\AppData\Local\AzureFunctionsTools\Releases\1.0.12.1\cli

它现在正在工作。

感谢所有参与帮助我解决这个问题的人!

于 2018-05-11T06:19:40.513 回答
1

我遇到了同样的错误,并将其追溯到 Newtonsoft.Json.dll 版本的差异。我通过从 GAC 卸载 Newtonsoft.Json 10.0 版解决了这个问题。(Azure Functions 需要 9.0。)

因此,在 Visual Studio 命令提示符下运行gacutil /l | findstr Newtonsoft,然后gacutil /u在您发现高于 9.0 的每个 DLL 版本上运行。

如果这不起作用,我建议从源代码运行 Azure Functions 工具 (func.exe)。从 克隆它https://github.com/Azure/azure-functions-core-tools/签出 v1.x 分支,然后运行 ​​Azure.Functions.Cli 项目,host start --pause-on-error并将 Azure 函数的输出文件夹作为命令行参数和工作目录。如果您在调试器中运行它并设置中断所有 CLR 异常,您应该能够很快找到您的问题。

于 2018-05-03T19:17:36.753 回答
0

在 v2 而不是 v1 上为我工作。我必须进入 .csproj 文件并将AzureFunctionsVersion添加到 PropertyGroup

<PropertyGroup>
  <TargetFramework>net461</TargetFramework>
  <AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
于 2019-04-11T05:20:54.520 回答