带有Cosmos DB输出本地开发主机的Azure HTTP功能触发器2.x失败 [英] Azure HTTP function trigger 2.x with Cosmos DB Output local dev host failing

本文介绍了带有Cosmos DB输出本地开发主机的Azure HTTP功能触发器2.x失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用azure函数2.x和dotnet内核开发一个http触发器,在对VS 2017 15.8.2进行最新更新之后,我在本地运行该函数时遇到以下错误

  1/9/2018 13:30:50]停止主机
[1/9/2018 13:31:06]读取主机配置文件'C: \用户\MattDouhan\源\repos\NWMposTransInput\NWMposTransInput\bin\Debug\netstandard2.0\host.json'
[1/9/2018 13:31:06 ]主机配置文件读取:
[1/9/2018 13:31:06] {}
[1/9/2018 13:31:06]启动主机(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]发生了ScriptHost错误
[1/9/2018 13:31:07] System.Private.CoreLib:无法从程序集中加载类型'Microsoft.Azure.WebJobs.Hosting.IWebJobsStartup' 'Microsoft.Azure.WebJobs.Host,版本= 3.0.0.0,文化= n eutral,PublicKeyToken = null。
[1/9/2018 13:31:07]正在停止主机

我正在运行函数核心工具2.0.1-Beta.35和运行时版本2.0.11960.0



函数如下所示

 使用System.IO; 
使用Microsoft.AspNetCore.Mvc;
使用Microsoft.Azure.WebJobs;
使用Microsoft.Azure.WebJobs.Extensions.Http;
使用Microsoft.AspNetCore.Http;
使用Microsoft.Azure.WebJobs.Host;
使用Newtonsoft.Json;
使用Microsoft.Extensions.Logging;
使用系统;

命名空间NWMposTransInput
{
public static class Function1
{
[FunctionName( Function1)]]
public static IActionResult Run([ HttpTrigger(AuthorizationLevel.Function, get, post,Route = null)]
HttpRequest请求,ILogger日志,
[CosmosDB(
databaseName: xxxx,
collectionName: yyyy,
ConnectionStringSetting = CosmosDbConnection)]动态文件,
ILogger log2)
{
log.LogInformation( C#HTTP触发函数处理了一个请求。 );

字符串名称= req.Query [名称];

字符串requestBody = new StreamReader(req.Body).ReadToEnd();
动态数据= JsonConvert.DeserializeObject(requestBody);
名称=名称??数据?。名称;

document = new {SSourceSystem = jongelSystem,
id = Guid.NewGuid(),
SSourceSystemVersion = 1.1,
STransactionId = 12345} ;

log.LogInformation($ C#队列触发函数插入一行);
log.LogInformation($ Description = {req.Body});

返回名称!= null
? (ActionResult)new OkObjectResult($ Hello,{name})
:new BadRequestObjectResult(请在查询字符串或请求正文中传递名称);
}
}

公共类NWCloudOrder
{
公共字符串ID {获取;组; }
公共字符串SSourceSystem {get;组; }
公共字符串SSourceSystemVersion {get;组; }
公共字符串STransactionId {get;组; }
}
}

---编辑---
确保我使用正确的运行时,现在会产生以下错误

  [2/9/2018 05:44:15]发生了ScriptHost错误
[2/9/2018 05:44:15] System.Private.CoreLib:无法加载文件或程序集'Microsoft.AspNetCore.Mvc.Abstractions,Version = 2.2.0.0,Culture =中性,PublicKeyToken = adb9793829ddae60'。无法找到或加载特定文件。 (来自HRESULT的异常:0x80131621)。 System.Private.CoreLib:无法加载文件或程序集 Microsoft.AspNetCore.Mvc.Abstractions,版本= 2.2.0.0,区域性=中性,PublicKeyToken = adb9793829ddae60。
[2/9/2018 05:44:15]正在停止主持人

我确实有安装了2.2.0-preview1-35029

解决方案

这是由于引用 Microsoft.Azure.WebJobs.Extensions .CosmosDB 在旧函数运行时 2.0.11960.0 3.0.1-beta1 / 2 c>。 Microsoft.NET.Sdk.Functions 1.0.19 Microsoft.Azure.WebJobs.Extensions.CosmosDB 3.0.1-beta2 取决于运行时 2.0.12050.0



选中此




更新


  1. 检查Cli输出,恐怕是旧版本2.0。正在使用11651.0。

     启动主机(HostId = xxx,InstanceId = xxx,Version = 2.0.11651.0,...) 

    转到%localappdata%\AzureFunctionsTools\Release ,您可能还会看到一个空文件夹 2.5.1



    由于某种原因下载失败像网络。再次重复上述步骤。如果不起作用,请尝试手动下载Cli。首先关闭VS。



    1)。打开%localappdata%\AzureFunctionsTools\feed.json 查找v2的最新下载网址。



    例如cli: https://functionscdn.azureedge.net/public/2.0.1-beta.36/Azure.Functions.Cli.win-x86.2.0.1-beta.36.zip



    2)。将解压缩的文件夹重命名为 cli ,并将其放在 2.5.1 下。



    3)。将 cli 文件夹中的 templates 文件夹移至 2.5.1



    4)。在 2.5.1 下创建manifest.json。(更改用户名)

      {
    ReleaseName: 2.5.1,
    CliEntrypointPath: C:\\Users\\UserName\\AppData\\Local\ \AzureFunctionsTools\\发布\\2.5.1\\cli\\func.exe,
    TemplatesDirectory: C:\\Users\\UserName \\AppData\\Local\\AzureFunctionsTools\\Release\\2.5.1\\templates,
    FunctionsExtensionVersion:〜2,
    SdkPackageVersion: 1.0.19
    }


  2. 功能SDK参考 Microsoft.AspNetCore.Mvc.Abstractions 2.1.0 通过设计。删除 2.2.0-preview1-35029 ,否则执行时可能会出错。

      Microsoft.Azure.WebJobs.Host:异常绑定参数 req。 System.Private.CoreLib:无法创建抽象类。 



I am developing a http trigger using azure functions 2.x and dotnet core, after the latest update to VS 2017 15.8.2 I am getting the following error when running the function locally

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

I am running Function Core tools 2.0.1-Beta.35 and runtime version 2.0.11960.0

The function looks as follows

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

--- EDIT --- Making sure I use the correct runtime this now produces the following error

[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

I do have 2.2.0-preview1-35029 installed

解决方案

It's caused by referencing Microsoft.Azure.WebJobs.Extensions.CosmosDB of latest version 3.0.1-beta1/2 in old function runtime 2.0.11960.0. Microsoft.NET.Sdk.Functions 1.0.19 and Microsoft.Azure.WebJobs.Extensions.CosmosDB 3.0.1-beta2 depends on runtime 2.0.12050.0.

Check this issue with relevant error info for breaking changes of latest runtime 2.0.12050.0.

If you don't want to move to latest runtime for now, downgrade Microsoft.Azure.WebJobs.Extensions.CosmosDB to 3.0.0-beta7 and Microsoft.NET.Sdk.Functions to 1.0.14.

Else just make sure VS consumes the latest function runtime 2.0.12050.0.

  1. On VS menus-> Extensions and Updates. Find Azure Functions and Web Jobs Tools. Make sure it's >= 15.8.5023.(Need to update VS to 15.8 first).

  2. Delete old Function Core tools(Cli) folder %localappdata%\AzureFunctionsTools.

  3. Restart VS and create a new Azure function. Wait at the creation dialog for VS to download new Cli and templates, until we see the tip change to Updates are ready.

Update

  1. Check Cli output, I am afraid older version 2.0.11651.0 is in use.

    Starting Host (HostId=xxx, InstanceId=xxx, Version=2.0.11651.0, ...)
    

    Go to %localappdata%\AzureFunctionsTools\Releases, you may also see an empty folder 2.5.1.

    The download failed due to some reason like network. Repeat the steps above again. If it doesn't work, try to download Cli manually. Close VS first.

    1). Open %localappdata%\AzureFunctionsTools\feed.json to find latest download url of v2.

    e.g. cli: https://functionscdn.azureedge.net/public/2.0.1-beta.36/Azure.Functions.Cli.win-x86.2.0.1-beta.36.zip.

    2). Rename unzipped folder as cli, put it under 2.5.1.

    3). Move templates folder in cli folder to 2.5.1.

    4). Create a manifest.json under 2.5.1.(Change your UserName)

    {
     "ReleaseName": "2.5.1",
     "CliEntrypointPath": "C:\\Users\\UserName\\AppData\\Local\\AzureFunctionsTools\\Releases\\2.5.1\\cli\\func.exe",
     "TemplatesDirectory": "C:\\Users\\UserName\\AppData\\Local\\AzureFunctionsTools\\Releases\\2.5.1\\templates",
     "FunctionsExtensionVersion": "~2",
     "SdkPackageVersion": "1.0.19"
    }
    

  2. Function SDK references Microsoft.AspNetCore.Mvc.Abstractions 2.1.0 by design. Remove 2.2.0-preview1-35029 or we may get error when executing.

    Microsoft.Azure.WebJobs.Host: Exception binding parameter 'req'. System.Private.CoreLib: Cannot create an abstract class.
    

这篇关于带有Cosmos DB输出本地开发主机的Azure HTTP功能触发器2.x失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆