Azure / azure-functions-vs-build-sdk

MSBuild task for Azure Functions
MIT License
96 stars 62 forks source link

Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type TraceWriter. Make sure the parameter Type is supported by the binding. 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.) #311

Open ashwineev opened 5 years ago

ashwineev commented 5 years ago

I have below cs project file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.27" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

framework version is 4.6

when I just use a default function v1 version Function is provided by the template public static class Function1 { [FunctionName("Function1")] public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request.");

        // parse query parameter
        string name = req.GetQueryNameValuePairs()
            .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
            .Value;

        if (name == null)
        {
            // Get request body
            dynamic data = await req.Content.ReadAsAsync<object>();
            name = data?.name;
        }

        return name == null
            ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
            : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
    }
}

sdk version is latest stable -"Microsoft.NET.Sdk.Functions" Version="1.0.27"

I get below error: when I debug locally. Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type TraceWriter. Make sure the parameter Type is supported by the binding. 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.)

ashwineev commented 5 years ago

I also tried installing dependent packages


  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="2.2.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.2.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.27" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="System.ValueTuple" Version="4.3.0" />
    <PackageReference Include="WindowsAzure.Storage" Version="7.2.1" />
  </ItemGroup>

```But still getting same error
sit-md commented 5 years ago

I'm seeing the same issue after cloning a repository to my dev machine. Other developers on the same project don't see that error and don't know where it comes from. Any assistance would be much appreciated.

sit-md commented 5 years ago

After a frustrating day of investigations (I updated the VS2017 and all the tooling around it, made sure that I'm not bouncing at the enterprise proxy, etc.) I found the problem. The SDK currently comes with version 1.0.10 of the Azure Function Tools. This version seems to have a bug that prevents the proper execution of v1 Azure Functions. Therefore I downloaded the latest version of the Azure Function Core Tools release from github and started the Script Host manually. It works perfectly then. To start it with debugging from VS2017 all you need to do is create a new profile in the Properties of the Startup Project under the tab "Debug" and point to the downloaded func.exe of the Azure Function Tools. Add the arguments "host start --port xxxx" and replace the "xxxx" with a port of your choice. Set the Working directory to $(TargetDir). From then on it's smooth sailing. Hope this helps everybody encountering the same issue.

sandeepnmenon commented 4 years ago

+1 Getting the same issue in Azure function v2 netcoreapp2.2

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    <RootNamespace>Microsoft.Crm.Assistant</RootNamespace>
    <AssemblyName>ActionCardFlowService</AssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AutofacOnFunctions" Version="1.0.14" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
    <PackageReference Include="System.Net.Http" Version="4.3.4" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>
sandeepnmenon commented 4 years ago

There was an issue were giving an empty host.json would add some default extension bundles in the azure function, causing it to fail loading. On removing the same (Extension bundles), it seems to work. Hence, for me providing a non-empty host.json resolved the issue.

For mitigation, removing the extension bundle from the function app settings can resolve the issue.

sudheeshix commented 4 years ago

I was able to fix this issue by adding the NuGet package Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator

varun5585 commented 4 years ago

Fixed by moving to the latest version of the SDK <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.35" />