问题描述
首先,我查看了其他带有相同错误消息的 SO 帖子,但似乎没有一个可以解决我的问题.我尝试了许多排列和选项.我的函数构建良好,但不会在 CLI 中运行,我收到以下神秘错误.MSFT 文档似乎也没有答案.
First off, I have looked at the other SO posts with the same error message and none seem to resolve my issue. I have tried many permutations and options. My function builds fine but will not run in the CLI, I get the following cryptic error. The MSFT documentation does not seem to have the answers either.
未找到工作职能.尝试公开您的工作类别和方法.如果您使用绑定扩展(例如 ServiceBus、Timers 等),请确保您已在启动代码中调用了扩展的注册方法(例如 config.UseServiceBus()、config.UseTimers() 等.).
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
我正在尝试运行计时器作业,然后将一组消息写入事件中心.我错过了什么?我已经为此奋斗了好几个小时.
I am trying to run a timer job and then write a collection of messages to an event hub. What am I missing? I have been fighting this for hours.
功能:
[FunctionName("CreateData")]
public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
[EventHub("murraytest", Connection = "evingest")] IAsyncCollector<string> myeventhub,
TraceWriter log)
{
await myeventhub.AddAsync("data1");
await myeventhub.AddAsync("data2");
await myeventhub.AddAsync("data3");
log.Info($"COMPLETED: {DateTime.Now}");
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"Eventhub": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "",
"evingest": "Endpoint=sb://example.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=LtcqBLT5VWjg0dGMdIvxCcEGs8902010Y6y14iGg="
}
}
包
function.json - 缺少任何 eventthub 绑定!
function.json - is missing any eventhub bindings!
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"schedule": "0 */5 * * * *",
"useMonitor": true,
"runOnStartup": false,
"name": "myTimer"
}
],
"disabled": false,
"scriptFile": "..\bin\AzFuncs.dll",
"entryPoint": "AzFuncs.Function1.Run"
}
推荐答案
我发现的另一个问题,尤其是当您从另一个项目或版本转换时.
Another gotcha I found especially if you are converting from another project or version.
在 VS csproj 文件中,确保存在 AzureFunctionsVersion
In the VS csproj file, make sure AzureFunctionsVersion is present
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
...etc
如果您正在修改缺少此功能的项目,该工具会自动添加此功能,但不会添加.希望这可以帮助您节省我花费的 3 个小时 :-).
the tooling adds this automatically but not added if you are modifying a project where this was missing. Hope this helps you save the 3 hours it cost me :-).
这篇关于未找到工作职能.尝试公开您的工作类别和方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!