Skip to content

Commit c2106ed

Browse files
authored
Avoid setting config properties that don't exist in .NET Framework variant (#3935)
* For .NET Framework applications using AWSSDK.Extensions.NETCore.Setup avoid setting service client config properties that are not in the .NET Framework variant of the SDK. * Add [MethodImpl(MethodImplOptions.NoInlining)] suggestion to avoid optimization triggering the runtime to check for HttpClientCacheSize too early
1 parent e37fd73 commit c2106ed

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

extensions/src/AWSSDK.Extensions.NETCore.Setup/AWSSDK.Extensions.NETCore.Setup.nuspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>AWSSDK.Extensions.NETCore.Setup</id>
55
<title>AWSSDK - Extensions for NETCore Setup</title>
6-
<version>4.0.2.0</version>
6+
<version>4.0.2.1</version>
77
<authors>Amazon Web Services</authors>
88
<description>Extensions for the AWS SDK for .NET to integrate with .NET Core configuration and dependency injection frameworks.</description>
99
<language>en-US</language>
@@ -14,19 +14,19 @@
1414

1515
<dependencies>
1616
<group targetFramework="netstandard2.0">
17-
<dependency id="AWSSDK.Core" version="4.0.0.12" />
17+
<dependency id="AWSSDK.Core" version="4.0.0.18" />
1818
<dependency id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.0" />
1919
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" />
2020
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" />
2121
</group>
2222
<group targetFramework="netcoreapp3.1">
23-
<dependency id="AWSSDK.Core" version="4.0.0.12" />
23+
<dependency id="AWSSDK.Core" version="4.0.0.18" />
2424
<dependency id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.0" />
2525
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" />
2626
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" />
2727
</group>
2828
<group targetFramework="net8.0">
29-
<dependency id="AWSSDK.Core" version="4.0.0.12" />
29+
<dependency id="AWSSDK.Core" version="4.0.0.18" />
3030
<dependency id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.0" />
3131
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.0" />
3232
<dependency id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" />

extensions/src/AWSSDK.Extensions.NETCore.Setup/ClientFactory.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
using System.Diagnostics.CodeAnalysis;
1818
using System.Linq;
1919
using System.Reflection;
20+
using System.Runtime.CompilerServices;
2021
using System.Xml.Linq;
2122
using Amazon.Runtime;
2223
using Amazon.Runtime.CredentialManagement;
2324
using Amazon.Runtime.Credentials.Internal;
25+
using Amazon.Util;
2426
using Microsoft.Extensions.Configuration;
2527
using Microsoft.Extensions.DependencyInjection;
2628
using Microsoft.Extensions.Logging;
@@ -295,10 +297,6 @@ private ClientConfig CreateConfig(AWSOptions options)
295297
{
296298
config.FastFailRequests = defaultConfig.FastFailRequests.Value;
297299
}
298-
if (defaultConfig.HttpClientCacheSize.HasValue)
299-
{
300-
config.HttpClientCacheSize = defaultConfig.HttpClientCacheSize.Value;
301-
}
302300
if (defaultConfig.IgnoreConfiguredEndpointUrls.HasValue)
303301
{
304302
config.IgnoreConfiguredEndpointUrls = defaultConfig.IgnoreConfiguredEndpointUrls.Value;
@@ -367,9 +365,28 @@ private ClientConfig CreateConfig(AWSOptions options)
367365
ProcessServiceSpecificSettings(config, defaultConfig.ServiceSpecificSettings);
368366
}
369367

368+
// It is possible that this library might be used in .NET Framework application. In that
369+
// case the SDK used at runtime will be the .NET Framework variant. To avoid getting
370+
// MissingMethodException exceptions for config properties that don't exist in
371+
// .NET Framework variant put the set calls in a separate method only called
372+
// if the SDK is not the .NET Framework variant.
373+
if (!AWSSDKUtils.IsNETFramework())
374+
{
375+
SetNETStandardAndAboveSettings(defaultConfig, config);
376+
}
377+
370378
return config;
371379
}
372380

381+
[MethodImpl(MethodImplOptions.NoInlining)]
382+
private void SetNETStandardAndAboveSettings(DefaultClientConfig defaultConfig, ClientConfig config)
383+
{
384+
if (defaultConfig.HttpClientCacheSize.HasValue)
385+
{
386+
config.HttpClientCacheSize = defaultConfig.HttpClientCacheSize.Value;
387+
}
388+
}
389+
373390
#if NET8_0_OR_GREATER
374391
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075",
375392
Justification = "The parent calling method uses the DynamicDependencyAttribute on the service client to ensure the public properties are not trimmed.")]

0 commit comments

Comments
 (0)