0
votes

we are trying to invoke azure cognitive services- translator api using azure function apps.We are getting the following error in the c# terminal:

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

Our C# code for reference:

 private const string key=" ";
                private static readonly HttpClient client=new HttpClient
                {
                   DefaultRequestHeaders={{"Ocp-Apim-Subscription-key",key}}
                };
                public static async Task Main()
                {
                    while(true){
                        var text=Console.ReadLine();
                        var translatedText=await Translate(text,"en");
                        Console.WriteLine(translatedText);
                    }
                }
                public static async Task<string> Translate(string text,string language){

                    var encodedText=WebUtility.UrlEncode(text);
                    var uri="https://api.microsofttranslator.com/V2/Http.svc/Translate?" + $"to={language}&text={encodedText}";
                    var result=await client.GetStringAsync(uri);
                    return XElement.Parse(result).Value;
                }

Also .csproj file code for reference:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <RootNamespace>transaltor_cognetive_service</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" >
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <PropertyGroup>
   <LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>
1
What do you mean by "using Azure function apps" ? The code you have posted is not an Azure function. We would need more details about what you are trying to do.MarleneHE
We configured azure in visual studio code ,by using azure functions,we created this projectThaarani S
Please look at @rickvdbosch's answer below. Your code is missing attributes and this is why the Functions Runtime cannot find your function. Could you be more explicit about the steps you took to create your project ? Did you use any Azure Functions template to create it ?MarleneHE

1 Answers

1
votes

As an addition to the MarleneHE's comment:

You're missing a FunctionNameAttribute and a TriggerAttribute. Without those, the Functions Runtime doesn't know which of the methods is the entry point, or how to trigger it.

In a class library, a function is a static method with a FunctionName and a trigger attribute

and

The FunctionName attribute marks the method as a function entry point. The name must be unique within a project, start with a letter and only contain letters, numbers, _, and -, up to 127 characters in length. Project templates often create a method named Run, but the method name can be any valid C# method name.

The trigger attribute specifies the trigger type and binds input data to a method parameter.