Skip to content

Commit

Permalink
Fix NullReferenceException on non-Windows platforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Nov 24, 2023
1 parent 96dd85a commit b13217f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/farlee2121/ResXResourceReader.NetStandard</RepositoryUrl>
<PackageTags>ResX;ResXResourceReader;System.Resources;ResXResourceWriter;netstandard</PackageTags>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions System.Resources.NetStandard/ResXDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ internal class AssemblyNamesTypeResolutionService : ITypeResolutionService
private Hashtable cachedAssemblies;
private Hashtable cachedTypes;

private static readonly string s_dotNetPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "dotnet\\shared");
private static readonly string s_dotNetPathX86 = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles(x86)"), "dotnet\\shared");
private static readonly string s_dotNetPath = Environment.GetEnvironmentVariable("ProgramFiles") is { } programFiles ? Path.Combine(programFiles, "dotnet", "shared") : null;
private static readonly string s_dotNetPathX86 = Environment.GetEnvironmentVariable("ProgramFiles(x86)") is { } programFilesX86 ? Path.Combine(programFilesX86, "dotnet", "shared") : null;

internal AssemblyNamesTypeResolutionService(AssemblyName[] names)
{
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public Type GetType(string name, bool throwOnError, bool ignoreCase)
/// </summary>
private bool IsDotNetAssembly(string assemblyPath)
{
return assemblyPath != null && (assemblyPath.StartsWith(s_dotNetPath, StringComparison.OrdinalIgnoreCase) || assemblyPath.StartsWith(s_dotNetPathX86, StringComparison.OrdinalIgnoreCase));
return assemblyPath != null && s_dotNetPath is not null && (assemblyPath.StartsWith(s_dotNetPath, StringComparison.OrdinalIgnoreCase) || assemblyPath.StartsWith(s_dotNetPathX86, StringComparison.OrdinalIgnoreCase));
}

public void ReferenceAssembly(AssemblyName name)
Expand Down

0 comments on commit b13217f

Please sign in to comment.