【发布时间】:2018-09-21 00:54:30
【问题描述】:
所以我一直在尝试创建一个简单的天蓝色函数,这将是一个 http 触发器“CreateUser”。
我做了另一个 http 触发器来简化问题,它看起来相当简单:
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
namespace TutoTableAzureTemplate
{
public static class TestTrigger
{
[FunctionName("TestTrigger")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
return req.CreateResponse(HttpStatusCode.OK, "This request arrived succcesfully");
}
}
}
这在模拟器上运行,给我带来以下错误:
Error indexing method 'TestTrigger.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type TraceWriter. Make sure the parameter Type is supported by the binding.
(我的模拟器版本是5.3)
我试图删除参数TraceWriter log,并且函数“运行”正常......直到我使用邮递员向它发送一个http请求,这带来了一个关于WebJobs的错误:
"System.InvalidOperationException : 'TestTrigger' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes? ... "
我想知道该属性是否是导致上一个问题的TraceWriter log,是否有办法将其带回此处...
哦,顺便说一句,我进入了某种地狱般的版本冲突,出于某种原因,我不得不使用 .NET Standard 2.0 而不是我之前使用的 .NET 461,按照教程的建议。
这是我的 .csproj :
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
<PackageReference Include="Microsoft.Azure.Storage.Common" Version="9.0.0.1-preview" />
<PackageReference Include="Microsoft.Azure.CosmosDB.Table" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
"Microsoft.Azure.CosmosDB.Table" 显然在 .NET Standard 2.0 中不可用,并且 .NET 461 版本在此处恢复,但“这只是一个警告”......而"Microsoft.Azure.Storage.Common" 仅在预览中。
这可能与某个地方的某个版本有关,但我在所有使用不同东西的教程中迷失了自己,而且由于我对 Azure 还很陌生,我不知道发生了什么......
【问题讨论】:
-
能否添加运行时版本:运行
func命令并复制Azure Functions Core Tools (xyz)和Function Runtime Version: xyz等行。 -
这有帮助吗?我在运行 .netstandard 2.0 时遇到了完全相同的问题:stackoverflow.com/questions/49672011/…
-
这就是我得到的:
Azure Functions Core Tools (1.0.10)和Function Runtime Version: 1.0.11612.0... 这里我只在模拟器上运行,但是当我将它发布到Azure 的云
标签: c# azure azure-functions azure-compute-emulator