Binding errors after updating Azure Functions project from 1.02 to 1.06 along with going from .NET Framework 4.7 to .NET standard 2.0
We have a number of projects built using the 1.02 functions SDK that originally built targeting .NET Framework 4.7. After retargeting to .NET standard 2.0 and updating them use the 1.06 functions SDK nuget package, debugging these projects show a bunch errors where the parameters cannot be bound to a specific type e.g. log to TraceWriter. We have classes that define multiple functions/entry points and the output indicates that only some of them have issues while others do not.
If we just kept these projects to target .NET Framework 4.7 and updated to them to use the 1.06 SDK then we don't get these issues at all.
Any idea what might be the cause of this as the method signatures of methods that work are generally identical
For example, this one works
[FunctionName(nameof(GetResizedImage))]
public static HttpResponseMessage GetResizedImage(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "image")] HttpRequestMessage req,
TraceWriter log)
{
...
}
but this one doesn't
[FunctionName(nameof(AddPodcastToCatalog))]
public static async Task<object> AddPodcastToCatalog(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "podcast/add")]HttpRequestMessage req,
TraceWriter log)
{
...
}
I'm trying to see if I understand the issue correctly.
So when you compile similar methods as above, if you target net standard 2.0, then you get an error binding TraceWriter, but if you target net framework 4.7 you don't get that error?
Can you paste the full error here you're getting? that'll help narrow down where the problem might be
I got a similar issue as well when I am changing the target of my Azure Function from .NET Framework 461 to NET Standard 2.0. When I try to debug the function in VS2017, the following message shows up in the AzureFunction CLI:
[2017-11-29 6:46:17 AM] A ScriptHost error has occurred
[2017-11-29 6:46:17 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'FunctionClass.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'traceWriter' 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.).
[2017-11-29 6:46:17 AM] Error indexing method 'FunctionClass.Run'
[2017-11-29 6:46:17 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'FunctionClass.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'traceWriter' 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.).
Here is my function signature:
[FunctionName("Balance")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "GET")]HttpRequestMessage req, TraceWriter traceWriter) {
......
}
Apologies for the late response but the error I got was pretty much the same one that peterjtan got
We are experiencing this same issue. Updates would be appreciated. Thanks!
Any update on this?
Switching away from Standard because of this 👎
I'm seeing this issue as well, both with TraceWriter as well as with my own custom types that I'm trying to inject.
for functions v1, you have to target full framework. All your other dependencies can target .NETStandard if you want, but the function project itself has to target full framework.
If you switch your function project to target .NETStandard, that will cause it to use functions v2 runtime, which has a slightly different object model. For instance, TraceWrite has been replaced with ILogger, HttpRequestMessage with HttpRequest, etc.
You can see the different set of dependencies Microsoft.NET.Sdk.Functions in here
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Newtonsoft.Json" Version="[10.0.3]" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="[3.0.0-beta4]" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="[3.0.0-beta4]" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="[3.0.0-beta4]" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="[1.0.0-beta2]" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<PackageReference Include="Newtonsoft.Json" Version="[9.0.1]" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="[2.1.0]" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="[2.1.0]" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="[1.0.0]" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
</ItemGroup>
also if you switch to .NETStandard, you want to add
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
to your csproj to tell VS to use the v2 runtime when you run or debug your app. Though note that the v2 runtime is still in beta
Still an issue, shouldn't be closed. Either the guidance is misleading or the tech is broke.
I am getting the same error when I try to run this function: public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, LastValueRow lastValueRow, TraceWriter log)
Class for LastValueRow - public class LastValueRow { public int RowId { get; set; } }
@goofballLogic what is still an issue? Have you read my reply above?
@nategurian what error are you getting? Do you mean you're getting an error referencing TraceWriter when your function app is targetting .NETStandard?
@ahmedelnably - Sorry meant to reply earlier I fixed my issue. It was my 'LastRowValue' parameter but I just added a Table Attribute to the parameter with corresponding tableName/ partition/rowKey. and it started working.
Thanks
Also didnt realize thread was closed...sorry!
@ahmelsayed yes I read your reply. We gave up on Standard for our stuff because we followed the standard Studio project templates and guidance and it didn't work. Those would need to change for this issue to be resolved IMO but hey it's your product.
Had the same problem and i downgraded Microsoft.NET.Sdk.Functions 1.0.13 to 1.0.11 (or below) and everything works. Why? who knows
Still having this issue ....