You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenAPI extension does not work when using EF Core >= 3.0 #173
Today I faced an issue when I started to use EF Core in my function app.
Error:
Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=3.1.16.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
at System.Reflection.RuntimeMethodInfo.GetParameters()
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.<>c.<GetHttpTriggerMethods>b__3_4(MethodInfo p)
at System.Linq.Utilities.<>c__DisplayClass1_0`1.<CombinePredicates>b__0(TSource x)
at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.GetHttpTriggerMethods(Assembly assembly)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Document.Build(Assembly assembly, OpenApiVersionType version)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctionProvider.RenderOpenApiDocument(HttpRequest req, String version, String extension, ExecutionContext ctx, ILogger log)
Steps to reproduce:
Create brand new Function App project in VS - .NET Core 3.1 / Function App v3
Same issue seems to occur with other extensions such as <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.15" /> that also has a dependency to Microsoft.Extensions.Logging.Abstractions.
(as long as you are injecting ILogger in your HttpTrigger functions).
A workaround seems to be using constructor-based injection for ILogger instead (though this is likely dependent on using IoC based functions)
Hi Nicolai Skovvart (@Skovvart), thank you for your suggestion. Your workaround works well If you are not using the OpenApiSecurity attribute. If I have it in my function decoration I get this error:
Exception has been thrown by the target of an invocation.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.GetSecurityOAuthFlows(OpenApiSecurityAttribute attr)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.GetOpenApiSecurityRequirement(MethodInfo element, NamingStrategy namingStrategy)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Document.Build(Assembly assembly, OpenApiVersionType version)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctionProvider.RenderOpenApiDocument(HttpRequest req, String version, String extension, ExecutionContext ctx, ILogger log)```
I am guessing that the the above is a separate issue, where your OpenApiSecurityAttribute implementation lacks a parameterless constructor (see #168 for some more context).
Activity
Skovvart commentedon Jul 12, 2021
Same issue seems to occur with other extensions such as
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.15" />that also has a dependency toMicrosoft.Extensions.Logging.Abstractions.(as long as you are injecting
ILoggerin your HttpTrigger functions).A workaround seems to be using constructor-based injection for
ILoggerinstead (though this is likely dependent on using IoC based functions)mogrodniczak commentedon Aug 5, 2021
Hi Nicolai Skovvart (@Skovvart), thank you for your suggestion. Your workaround works well If you are not using the OpenApiSecurity attribute. If I have it in my function decoration I get this error:
Skovvart commentedon Aug 5, 2021
I am guessing that the the above is a separate issue, where your
OpenApiSecurityAttributeimplementation lacks a parameterless constructor (see #168 for some more context).tkhadimullin commentedon Oct 6, 2021
Not sure if this is still relevant, I was able to work around this issue by downgrading EF Core to
3.1.13DanielHead commentedon Nov 29, 2021
I'm facing the same issues, could it be related to #281?