【发布时间】:2018-09-01 13:37:28
【问题描述】:
我正在使用 azure functions 2.x 和 dotnet core 开发一个 http 触发器,在最新更新到 VS 2017 15.8.2 后,我在本地运行该函数时收到以下错误
1/9/2018 13:30:50] Stopping Host
[1/9/2018 13:31:06] Reading host configuration file 'C:\Users\MattDouhan\source\repos\NWMposTransInput\NWMposTransInput\bin\Debug\netstandard2.0\host.json'
[1/9/2018 13:31:06] Host configuration file read:
[1/9/2018 13:31:06] {}
[1/9/2018 13:31:06] Starting Host (HostId=desktop7cks1do-260439321, InstanceId=5fd41a43-b3ca-47e4-adf6-320d40fa9613, Version=2.0.11960.0, ProcessId=13156, AppDomainId=1, Debug=False, ConsecutiveErrors=5, StartupCount=6, FunctionsExtensionVersion=)
[1/9/2018 13:31:07] A ScriptHost error has occurred
[1/9/2018 13:31:07] System.Private.CoreLib: Could not load type 'Microsoft.Azure.WebJobs.Hosting.IWebJobsStartup' from assembly 'Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null'.
[1/9/2018 13:31:07] Stopping Host
我正在运行 Function Core 工具 2.0.1-Beta.35 和运行时版本 2.0.11960.0
函数如下所示
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;
using Microsoft.Extensions.Logging;
using System;
namespace NWMposTransInput
{
public static class Function1
{
[FunctionName("Function1")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
HttpRequest req, ILogger log,
[CosmosDB(
databaseName: "xxxx",
collectionName: "yyyy",
ConnectionStringSetting = "CosmosDbConnection")]out dynamic document,
ILogger log2)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
document = new { SSourceSystem = "jongelSystem",
id = Guid.NewGuid(),
SSourceSystemVersion = "1.1",
STransactionId = "12345"};
log.LogInformation($"C# Queue trigger function inserted one row");
log.LogInformation($"Description={req.Body}");
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
public class NWCloudOrder
{
public string Id { get; set; }
public string SSourceSystem { get; set; }
public string SSourceSystemVersion { get; set; }
public string STransactionId { get; set; }
}
}
--- 编辑 --- 确保我使用正确的运行时现在会产生以下错误
[2/9/2018 05:44:15] A ScriptHost error has occurred
[2/9/2018 05:44:15] System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[2/9/2018 05:44:15] Stopping Host
我确实安装了 2.2.0-preview1-35029
【问题讨论】:
-
请编辑您的问题以包含您的 Azure 函数的详细信息。没有代码,只有一些错误日志语句,很难猜测会发生什么。另外,您将此标记为
azure-cosmosdb- 这是否相关?请在编辑时说明。 -
按要求澄清
标签: azure azure-functions azure-cosmosdb azure-functions-runtime azure-functions-core-tools