如何解决Azure Function门户部署错误?

问题描述 投票:-1回答:1
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.Azure.EventHubs;
using System;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    const string EventHubConnectionString = "XXXXXXXXX";
    var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString)
        {
            EntityPath = "tester",
            TransportType = Microsoft.Azure.EventHubs.TransportType.AmqpWebSockets
        };

    EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

    for(int i=0;i<1;i++)
    {    
        try
            {
                string message = JsonConvert.SerializeObject("Message : "+i);
                log.LogInformation($"Sending => {message}");
                await eventHubClient.SendAsync(new     EventData(System.Text.Encoding.UTF8.GetBytes(message)));
            }
            catch (Exception exception)
            {
                log.LogInformation($"{DateTime.Now} > Exception: {exception.Message}");
            }    
    }

    await eventHubClient.CloseAsync();

    return name != null
    ? (ActionResult)new OkObjectResult($"Hello, {name}")
    : new BadRequestObjectResult("Please pass a name on the query string or in the request body"); 
}

[[Error]函数编译错误Microsoft.CodeAnalysis.Scripting.CompilationErrorException:无法还原包在异步Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.CreateFunctionTarget(CancellationToken cancellingToken)在C:\ azure-webjobs-sdk-script \ src \ WebJobs.Script \ Description \ DotNet \ DotNetFunctionInvoker.cs:314在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在异步Microsoft.Azure.WebJobs.Script.Description.FunctionLoader`1.GetFunctionTargetAsync [T](Int32 tryCount)在C:\ azure-webjobs-sdk-script \ src \ WebJobs.Script \ Description \ FunctionLoader.cs:55在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在异步Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.GetFunctionTargetAsync(Boolean isInvocation)在C:\ azure-webjobs-sdk-script \ src \ WebJobs.Script \ Description \ DotNet \ DotNetFunctionInvoker.cs:1832020-01-16T13:57:16.899 [错误]执行了'Functions.Sender'(失败,ID = ca934efb-3cd5-4fa6-bc61-f7f99b8ae362)无法还原软件包

Function.proj

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

    <PackageReference Include="Microsoft.Azure.EventHubs" Version="4.1.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System" />

</ItemGroup>
</Project>
c# azure function azure-eventhub
1个回答
0
投票

我创建了另一个函数,编写代码以将事件发送到eventhub,仅使用此程序包上载function.proj并仅导入此程序包,并且可以使用。

© www.soinside.com 2019 - 2024. All rights reserved.