Open impworks opened 1 month ago
The root of the problem seems to be a nullable argument from a HttpTrigger
, like string? arg
in the example below:
[FunctionName("DoStuff")]
public Task DoStuff([HttpTrigger("get", Route = "v1/DoStuff/{arg?}")] HttpRequest req, string? arg, ILogger log)
{
return Task.CompletedTask;
}
When changing the type from string?
to just string
, the compilation succeeds.
Thanks for updating will check and update the same.
I'm getting this issue but I don't have any HttpTrigger decorated functions with a nullable route segment in fact all of my HttpTrigger functions are parameterless except an "HttpRequest req" parameter
I checked and found working fine .can you send your api url with arg
I'm getting the same going from v4.0.0 to v4.4.0. Haven't found out what triggers it yet. No [HttpTrigger] and no nullable argument types.
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : System.NullReferenceException: Object reference not set to an instance of an object.
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at MakeFunctionJson.AttributeExtensions.IsWebJobsAttribute(CustomAttribute attribute) in /_/src/Microsoft.NET.Sdk.Functions.Generator/AttributeExtensions.cs:line 52
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at MakeFunctionJson.MethodInfoExtensions.<>c.<GetOutputBindingsFromReturnAttribute>b__7_0(CustomAttribute a) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 101
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at MakeFunctionJson.MethodInfoExtensions.GetOutputBindingsFromReturnAttribute(MethodDefinition method) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 101
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at MakeFunctionJson.MethodInfoExtensions.ToFunctionJson(MethodDefinition method, String assemblyPath) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 65
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 140
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 194
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : at MakeFunctionJson.FunctionJsonConverter.TryRun() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 87
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Error generating functions metadata
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :
3>C:\Users\mh\.nuget\packages\microsoft.net.sdk.functions\4.4.0\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Metadata generation failed.
if possible can you share the code snippet or still you getting the same issue.
I'll try to find at repro, and post it if/when I do. But with no indication of what is actually going wrong, there's not much to go on.
I can understand wanting to find a root cause.
But still it seems like preventing the NullReferenceException
in AttributeExtensions.IsWebJobsAttribute
should be a straight forward fix.
Just tested with 4.1.0 -> 4.3.0 and all have the same error.
Cause of error seems to be using a tuple return value in my case:
[FunctionName("SomeActivity")]
public async Task<(int Id, MyState State, string Identifier)> ExecuteAsync([ActivityTrigger] MyArguments args, CancellationToken cancellationToken)
Fixed by returning class type instead.
I had a similar error. I commented out all the [FunctionName] attributes in my project and added them back in until I found the one causing the error.
I my case the problem was a function that returned a Task<List<Something>?>
(Don't ask me why the list is nullable😅. It is legacy code). After removing the nullable (which also caused a warning) it built successfully.
Now the return type is Task<List<Something>>
Still a problem
I also experienced the issue with a return value of IEnumerable<KeyValuePair<string, string>>
(assuming the KeyValuePair
was the issue)
I also encountered this issue because I enabled
After updating the project to .NET 8 I started getting build errors:
The NuGet package version is the latest currently available (4.4.0).