Skip to content

Commit 555c401

Browse files
committed
Bump dotnet and fix platform compat issues
1 parent 6c4a773 commit 555c401

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "6.0.100-alpha.1.21063.4"
44
},
55
"tools": {
6-
"dotnet": "6.0.100-alpha.1.20523.3",
6+
"dotnet": "6.0.100-alpha.1.21063.4",
77
"runtimes": {
88
"dotnet/x64": [
99
"2.1.23",

src/DataProtection/DataProtection/src/DataProtectionServiceCollectionExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Diagnostics;
6+
using System.Runtime.InteropServices;
7+
using System.Runtime.Versioning;
58
using Microsoft.AspNetCore.Cryptography.Cng;
69
using Microsoft.AspNetCore.DataProtection;
710
using Microsoft.AspNetCore.DataProtection.Infrastructure;
@@ -67,6 +70,8 @@ private static void AddDataProtectionServices(IServiceCollection services)
6770
{
6871
if (OSVersionUtil.IsWindows())
6972
{
73+
// Assertion for platform compat analyzer
74+
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
7075
services.TryAddSingleton<IRegistryPolicyResolver, RegistryPolicyResolver>();
7176
}
7277

src/DataProtection/DataProtection/src/EphemeralDataProtectionProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics;
66
using System.Runtime.InteropServices;
7+
using System.Runtime.Versioning;
78
using Microsoft.AspNetCore.Cryptography.Cng;
89
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
910
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
@@ -47,6 +48,8 @@ public EphemeralDataProtectionProvider(ILoggerFactory loggerFactory)
4748
IKeyRingProvider keyringProvider;
4849
if (OSVersionUtil.IsWindows())
4950
{
51+
// Assertion for platform compat analyzer
52+
Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
5053
// Fastest implementation: AES-256-GCM [CNG]
5154
keyringProvider = new EphemeralKeyRing<CngGcmAuthenticatedEncryptorConfiguration>(loggerFactory);
5255
}

src/DataProtection/DataProtection/src/KeyManagement/XmlKeyManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Runtime.CompilerServices;
1010
using System.Runtime.InteropServices;
11+
using System.Runtime.Versioning;
1112
using System.Threading;
1213
using System.Xml;
1314
using System.Xml.Linq;

src/DataProtection/DataProtection/src/LoggingExtensions.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System;
55
using System.Diagnostics.CodeAnalysis;
66
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
using System.Runtime.Versioning;
79
using System.Xml.Linq;
810
using Microsoft.AspNetCore.DataProtection;
911
using Microsoft.Win32;
@@ -95,7 +97,7 @@ internal static class LoggingExtensions
9597

9698
private static Action<ILogger, string, Exception?> _writingDataToFile;
9799

98-
private static Action<ILogger, RegistryKey, string, Exception?> _readingDataFromRegistryKeyValue;
100+
private static Action<ILogger, RegistryKey, string, Exception?>? _readingDataFromRegistryKeyValue;
99101

100102
private static Action<ILogger, string, string, Exception?> _nameIsNotSafeRegistryValueName;
101103

@@ -305,10 +307,15 @@ static LoggingExtensions()
305307
eventId: new EventId(39, "WritingDataToFile"),
306308
logLevel: LogLevel.Information,
307309
formatString: "Writing data to file '{FileName}'.");
308-
_readingDataFromRegistryKeyValue = LoggerMessage.Define<RegistryKey, string>(
309-
eventId: new EventId(40, "ReadingDataFromRegistryKeyValue"),
310-
logLevel: LogLevel.Debug,
311-
formatString: "Reading data from registry key '{RegistryKeyName}', value '{Value}'.");
310+
311+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
312+
{
313+
_readingDataFromRegistryKeyValue = LoggerMessage.Define<RegistryKey, string>(
314+
eventId: new EventId(40, "ReadingDataFromRegistryKeyValue"),
315+
logLevel: LogLevel.Debug,
316+
formatString: "Reading data from registry key '{RegistryKeyName}', value '{Value}'.");
317+
}
318+
312319
_nameIsNotSafeRegistryValueName = LoggerMessage.Define<string, string>(
313320
eventId: new EventId(41, "NameIsNotSafeRegistryValueName"),
314321
logLevel: LogLevel.Debug,
@@ -662,9 +669,13 @@ public static void WritingDataToFile(this ILogger logger, string finalFilename)
662669
_writingDataToFile(logger, finalFilename, null);
663670
}
664671

672+
[SupportedOSPlatform("windows")]
665673
public static void ReadingDataFromRegistryKeyValue(this ILogger logger, RegistryKey regKey, string valueName)
666674
{
667-
_readingDataFromRegistryKeyValue(logger, regKey, valueName, null);
675+
if (_readingDataFromRegistryKeyValue != null)
676+
{
677+
_readingDataFromRegistryKeyValue(logger, regKey, valueName, null);
678+
}
668679
}
669680

670681
public static void NameIsNotSafeRegistryValueName(this ILogger logger, string friendlyName, string newFriendlyName)

0 commit comments

Comments
 (0)