Skip to content

Commit d87c1b3

Browse files
Fix possible NRE (netcoreapp3.1 only?)
1 parent 0e0b267 commit d87c1b3

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/AspNetCore/OData/src/Asp.Versioning.OData.ApiExplorer/ApiExplorer/ODataApiDescriptionProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ public virtual void OnProvidersExecuted( ApiDescriptionProviderContext context )
102102
for ( var i = results.Count - 1; i >= 0; i-- )
103103
{
104104
var result = results[i];
105-
var metadata = result.ActionDescriptor.EndpointMetadata.OfType<IODataRoutingMetadata>().ToArray();
105+
106+
if ( result.ActionDescriptor.EndpointMetadata is not IList<object> endpointMetadata )
107+
{
108+
continue;
109+
}
110+
111+
var metadata = endpointMetadata.OfType<IODataRoutingMetadata>().ToArray();
106112
var notOData = metadata.Length == 0;
107113

108114
if ( notOData )

src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/VersionedApiDescriptionProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ private static bool IsUnversioned( ActionDescriptor action )
179179
{
180180
var endpointMetadata = action.EndpointMetadata;
181181

182+
if ( endpointMetadata == null )
183+
{
184+
return true;
185+
}
186+
182187
for ( var i = 0; i < endpointMetadata.Count; i++ )
183188
{
184189
if ( endpointMetadata[i] is ApiVersionMetadata )

src/AspNetCore/WebApi/src/Asp.Versioning.Mvc/Abstractions/ActionDescriptorExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public static ApiVersionMetadata GetApiVersionMetadata( this ActionDescriptor ac
2424

2525
var endpointMetadata = action.EndpointMetadata;
2626

27+
if ( endpointMetadata == null )
28+
{
29+
return ApiVersionMetadata.Empty;
30+
}
31+
2732
for ( var i = 0; i < endpointMetadata.Count; i++ )
2833
{
2934
if ( endpointMetadata[i] is ApiVersionMetadata metadata )
@@ -39,6 +44,12 @@ internal static void AddOrReplaceApiVersionMetadata( this ActionDescriptor actio
3944
{
4045
var endpointMetadata = action.EndpointMetadata;
4146

47+
if ( endpointMetadata == null )
48+
{
49+
action.EndpointMetadata = new List<object>() { value };
50+
return;
51+
}
52+
4253
for ( var i = 0; i < endpointMetadata.Count; i++ )
4354
{
4455
if ( endpointMetadata[i] is not ApiVersionMetadata )

0 commit comments

Comments
 (0)