From 56a036bca3b2d97ac099cae72d8d7017a0a4acca Mon Sep 17 00:00:00 2001 From: Jay Bazuzi Date: Fri, 14 Aug 2026 03:17:09 -0700 Subject: [PATCH] Fix PathTooLongException in analyzer tests Use Path.PathSeparator instead of hardcoded ';' to properly split TRUSTED_PLATFORM_ASSEMBLIES, and add validation to skip invalid paths. This prevents malformed or concatenated assembly paths from being processed, which was causing PathTooLongException during type initialization on the test runner. Fixes the failing analyzer tests: - EfQueryStandaloneMethodAnalyzerTests - EfQueryableModelTypeAnalyzerTests --- .../EfQueryStandaloneMethodAnalyzerTests.cs | 7 +++++-- .../EfQueryableModelTypeAnalyzerTests.cs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryStandaloneMethodAnalyzerTests.cs b/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryStandaloneMethodAnalyzerTests.cs index 498043b..6a21bb9 100644 --- a/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryStandaloneMethodAnalyzerTests.cs +++ b/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryStandaloneMethodAnalyzerTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Immutable; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -24,8 +25,10 @@ internal static class Verifier { private static readonly ImmutableArray RuntimeReferences = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) - .Split(';') - .Where(path => path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) + .Split(Path.PathSeparator) + .Where(path => !string.IsNullOrWhiteSpace(path) && + path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) && + File.Exists(path)) .Select(path => (MetadataReference)MetadataReference.CreateFromFile(path)) .Append(MetadataReference.CreateFromFile(typeof(Microsoft.EntityFrameworkCore.DbContext).Assembly.Location)) .ToImmutableArray(); diff --git a/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryableModelTypeAnalyzerTests.cs b/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryableModelTypeAnalyzerTests.cs index 2864e3d..3eeea9f 100644 --- a/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryableModelTypeAnalyzerTests.cs +++ b/src/ApprovalTests.EntityFramework.Analyzers.Tests/EfQueryableModelTypeAnalyzerTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Immutable; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -29,8 +30,10 @@ internal static class ModelTypeVerifier { private static readonly ImmutableArray RuntimeReferences = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) - .Split(';') - .Where(path => path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) + .Split(Path.PathSeparator) + .Where(path => !string.IsNullOrWhiteSpace(path) && + path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) && + File.Exists(path)) .Select(path => (MetadataReference)MetadataReference.CreateFromFile(path)) .Append(MetadataReference.CreateFromFile(typeof(Microsoft.EntityFrameworkCore.DbContext).Assembly.Location)) .ToImmutableArray();