Azure / Azure/azure-functions-openapi-extension
Microsoft.Azure.Functions.Worker.Extensions.OpenApi throws System.IO.FileNotFoundException
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
I migrated a function app from .net 6.0 to 8.0 with the Upgrade wizard on Visual Studio 2022, on doing so, I changed the model from utilizing `Microsoft.Azure.WebJobs.Extensions.OpenApi` to `Microsoft.Azure.Functions.Worker.Extensions.OpenApi`.
My project relies on third party libraries that are outdated, but still usable for referencing models.
**To Reproduce**
Steps to reproduce the behavior:
1. Run function app
2. Open link for 'RenderSwaggerUI'
3. See error
**Expected behavior**
Should be able to see Swagger loading properly, as it's seen with `Microsoft.Azure.WebJobs.Extensions.OpenApi`, skipping any unused types custom attributes. Feels the code traverses all types regardless of those being used in any parts of swagger.
**Screenshots**
**Environment (please complete the following information, if applicable):**
- OS: Windows 11 Pro Versão 23H2 (Compilação do Sistema Operacional 22631.2715)
- Browser Edge
- Version 119.0.2151.72 (Compilação oficial) (64 bits)
**Additional context**
Add any other context about the problem here.
***Stack Trace***
```log
at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) in /_/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs:line 1341
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs:line 261
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs:line 1389
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs:line 1284
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs:line 1151
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs:line 998
at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit) in /_/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs:line 463
at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit) in /_/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs:line 522
at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](MemberInfo element, Boolean inherit) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/CustomAttributeExtensions.cs:line 56
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.MemberInfoExtensions.ExistsCustomAttribute[T](MemberInfo element, Boolean inherit) in D:\source\azure-functions-openapi-extension\src\Microsoft.Azure.WebJobs.Extensions.OpenApi.Core\Extensions\MemberInfoExtensions.cs:line 27
```
Contributor guide
Research direction
Reproduce the failure by running the function app and opening the RenderSwaggerUI link, then inspect MemberInfoExtensions.cs at line 27 and the accompanying reflection stack trace. Done means Swagger UI loads successfully for the reported .NET 8 migration scenario without the System.IO.FileNotFoundException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100