Skip to content

Commit 7797232

Browse files
committed
Remove RuntimeInformation on full framework. Fixes #381
1 parent 288a3fe commit 7797232

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/MySqlConnector/MySqlConnector.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net46' ">
2424
<PackageReference Include="System.Buffers" Version="4.3.0" />
25-
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
2625
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.3.0" />
2726
<Reference Include="System.Data" />
2827
<Reference Include="System.Transactions" />

src/MySqlConnector/Serialization/MySqlSession.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -887,20 +887,16 @@ private static byte[] CreateConnectionAttributes()
887887
attributesWriter.WriteLengthEncodedString(typeof(MySqlSession).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
888888
try
889889
{
890-
var os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Windows" :
891-
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "Linux" :
892-
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "macOS" : null;
893-
var osDetails = RuntimeInformation.OSDescription;
894-
var platform = RuntimeInformation.ProcessArchitecture.ToString();
890+
Utility.GetOSDetails(out var os, out var osDescription, out var architecture);
895891
if (os != null)
896892
{
897893
attributesWriter.WriteLengthEncodedString("_os");
898894
attributesWriter.WriteLengthEncodedString(os);
899895
}
900896
attributesWriter.WriteLengthEncodedString("_os_details");
901-
attributesWriter.WriteLengthEncodedString(osDetails);
897+
attributesWriter.WriteLengthEncodedString(osDescription);
902898
attributesWriter.WriteLengthEncodedString("_platform");
903-
attributesWriter.WriteLengthEncodedString(platform);
899+
attributesWriter.WriteLengthEncodedString(architecture);
904900
}
905901
catch (PlatformNotSupportedException)
906902
{

src/MySqlConnector/Utility.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ public static void WriteUtf8(this BinaryWriter writer, string value, int startIn
220220
}
221221
}
222222

223+
#if NET45 || NET46
224+
public static bool IsWindows() => Environment.OSVersion.Platform == PlatformID.Win32NT;
225+
226+
public static void GetOSDetails(out string os, out string osDescription, out string architecture)
227+
{
228+
os = Environment.OSVersion.Platform == PlatformID.Win32NT ? "Windows" :
229+
Environment.OSVersion.Platform == PlatformID.Unix ? "Linux" :
230+
Environment.OSVersion.Platform == PlatformID.MacOSX ? "macOS" : null;
231+
osDescription = Environment.OSVersion.VersionString;
232+
architecture = IntPtr.Size == 8 ? "X64" : "X86";
233+
}
234+
#else
223235
public static bool IsWindows()
224236
{
225237
try
@@ -232,5 +244,15 @@ public static bool IsWindows()
232244
return false;
233245
}
234246
}
247+
248+
public static void GetOSDetails(out string os, out string osDescription, out string architecture)
249+
{
250+
os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Windows" :
251+
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "Linux" :
252+
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "macOS" : null;
253+
osDescription = RuntimeInformation.OSDescription;
254+
architecture = RuntimeInformation.ProcessArchitecture.ToString();
255+
}
256+
#endif
235257
}
236258
}

0 commit comments

Comments
 (0)