Skip to content

OpenAPI extension does not work when using EF Core >= 3.0 #173

Open

Description

Hi all,

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:

  1. Create brand new Function App project in VS - .NET Core 3.1 / Function App v3
  2. Install OpenAPI Extension
  3. Run function app
  4. Open http://localhost:7071/api/openapi/1.0 in the web browser - it does work
  5. Install EF Core 3.1.6
  6. Run function app
  7. Open http://localhost:7071/api/openapi/1.0 in the web browser - returns an error

so EF Core 3.1.16 requires Microsoft.Extensions.Logging.Abstractions >= 3.1.16

It seems that the OpenAPI extension can work only when it is < 3.0.

Do you have any insight into it?

Activity

  1. Skovvart commented on Jul 12, 2021

    @Skovvart

    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)

  2. mogrodniczak commented on Aug 5, 2021

    @mogrodniczak
    Author

    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)```
    
  3. Skovvart commented on Aug 5, 2021

    @Skovvart

    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).

  4. tkhadimullin commented on Oct 6, 2021

    @tkhadimullin

    Not sure if this is still relevant, I was able to work around this issue by downgrading EF Core to 3.1.13

  5. DanielHead commented on Nov 29, 2021

    @DanielHead

    I'm facing the same issues, could it be related to #281?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions