No job functions found. Try making your job classes and methods public

只谈情不闲聊 提交于 2019-11-30 17:54:56

问题


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.

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.

Function:

    [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="    } } 

Packages

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

回答1:


You should upgrade to the latest Microsoft.NET.Sdk.Functions (1.0.6 as of today) and Microsoft.Azure.WebJobs.Service.Bus (2.1.0-beta4 if running on full framework). You might need to remove the ServiceBus reference first in order to upgrade SDK.

The Microsoft.Azure.Eventhubs package also needs to be removed. All relevant types etc are in Microsoft.Azure.WebJobs.Service.Bus

Also remember to check "Include prerelease" in the package manager in order to find 2.1.0-beta4.




回答2:


Another gotcha I found especially if you are converting from another project or version.

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 

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 :-).




回答3:


If you debug/run from Visual Studio (F5), somehow, even with latest Microsoft.NET.Sdk.Functions (v1.0.28), its not able to detect AzureFunctions defined in the project.

I root caused the issue to Project properties > Debug > Working Directory is not set somehow by default. Set it to the actual directory where binaries are found and your AzureFunctions becomes available for debug.

PS, this would add launchSettings.json /profiles/{projectName}/workingDirectory=/objd/amd64/



来源:https://stackoverflow.com/questions/47682760/no-job-functions-found-try-making-your-job-classes-and-methods-public

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!