Azure / azure-functions-vs-build-sdk

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

Error generating metadata when using a Disable attribute provider #480

Open drdamour opened 3 years ago

drdamour commented 3 years ago
[Disable(typeof(DisableProvider))]
        [FunctionName(nameof(ProcessAgvanceProductsScheduled))]
        public async Task ProcessAgvanceProductsScheduled(

with

    public class DisableProvider
    {
        public bool IsDisabled(
            MethodInfo method
        )
        {
            return true;
        }
    }

now if my DisableProvider is in a referenced project i get:

1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : System.ArgumentException: Object of type 'Mono.Cecil.TypeReference' cannot be converted to type 'System.Type'.
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.TypeUtility.ToReflection(CustomAttribute customAttribute)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.MethodInfoExtensions.GetDisabled(MethodDefinition method)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.MethodInfoExtensions.HasUnsuportedAttributes(MethodDefinition method, String& error)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext()
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :    at MakeFunctionJson.FunctionJsonConverter.TryRun()
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Error generating functions metadata
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Metadata generation failed.

if it's in the same project assembly i get:

1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : the constructor 'DisableAttribute(Type)' is not supported.
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Error generating functions metadata
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :
1>C:\Users\damourc\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Metadata generation failed.

any advice?

Obi-Dann commented 2 years ago

I am also getting this issue when trying to use DisableAttribute with provider. Going to ping one of the contributors to hopefully get some response since the issue was reported almost a year ago. cc @ahmelsayed

Obi-Dann commented 2 years ago

Done a bit of digging, the validation for DisableAttribute with type provider was added in https://github.com/Azure/azure-functions-vs-build-sdk/issues/85 There was a comment from @MikeStall describing the behaviour https://github.com/Azure/azure-functions-vs-build-sdk/issues/85#issuecomment-319843602

The driving factor here is that whatever the tooling emits cooperates with the existing function.json spec around disabled; and if it's not supported in function.json today, then the tooling emits a error.

From what I can understand DisableAttribute with type provider is not supported by function.json, but supported by function host at runtime (as well as the setting)

https://github.com/Azure/azure-webjobs-sdk/blob/da78eb482e5b2d44fae6b911bc11bddefff7abd7/src/Microsoft.Azure.WebJobs.Host/Listeners/HostListenerFactory.cs#L143-L160

So perhaps, the sdk should just ignore the DisableAttribute with provider type, output nothing into function.json and let webjobs host handle it?

cataggar commented 2 years ago

I just ran into this. When I build, it is giving me this error:

1>C:\Users\cataggar\.nuget\packages\microsoft.net.sdk.functions\4.0.1\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : the constructor 'DisableAttribute(Type)' is not supported.
1>C:\Users\cataggar\.nuget\packages\microsoft.net.sdk.functions\4.0.1\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Error generating functions metadata
1>C:\Users\cataggar\.nuget\packages\microsoft.net.sdk.functions\4.0.1\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error :
1>C:\Users\cataggar\.nuget\packages\microsoft.net.sdk.functions\4.0.1\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Metadata generation failed.

from C:\Users\cataggar.nuget\packages\microsoft.net.sdk.functions\4.0.1\build\Microsoft.NET.Sdk.Functions.Build.targets

I'm using Microsoft.NET.Sdk.Function 4.0.1 image

cataggar commented 2 years ago

It looks like the error the constructor 'DisableAttribute(Type)' is not supported. is from here: https://github.com/Azure/azure-functions-vs-build-sdk/commit/e01723e42828899efa92cf89c067d9fb10504036#diff-deef5eafcb2f79e9b4fa343f175b8c0ad462fe43112394ebb47e5b1a563af62cR147

fabiocav commented 2 years ago

Indeed. This is not a supported constructor in the context of Functions. We'll create an analyzer for this providing clearer information when this is used (with a code suggestion).

fabiocav commented 2 years ago

@kashimiz will be creating an issue to track the analyzer work and closing this once that is done.

tomasopye commented 1 year ago

So this sounds like we cannot use a DisableProvider with the DisableAttribute until this is resolved, is that correct? And if so, what release is this planned for?

VenkatSappidi commented 1 year ago

Any work around for this issue? I am having same one

leotuna commented 12 months ago

Updates?