Skip to content

Handle TypeLoadException in config property scans - #5293

Merged
tig merged 2 commits into
tui-cs:developfrom
duskfold:duskfold/fix-configproperty-typeload
May 12, 2026
Merged

tig merged 2 commits into
tui-cs:developfrom
duskfold:duskfold/fix-configproperty-typeload

Conversation

@duskfold

Copy link
Copy Markdown
Contributor

Summary

  • handle TypeLoadException while checking foreign properties for ConfigurationPropertyAttribute
  • expose the assembly-scan helper so the failure can be proven directly in tests
  • add deterministic fixture-backed proof for the custom-attribute metadata failure shape

Why

This supersedes the closed #5124 thread with the corrected proof.

The failure is not a plain Assembly.GetTypes() repro on modern CoreCLR. The real downstream failure happens later in the same config-host scan, when ConfigProperty.Initialize() reflects over properties from foreign loaded assemblies and PropertyInfo.GetCustomAttribute(...) throws a plain TypeLoadException while resolving broken custom-attribute metadata.

The new test proves that exact shape with two fixture assemblies:

  • ConsumerLib.dll is compiled against a provider assembly that contains System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute
  • at runtime the test loads a same-identity replacement provider assembly that no longer contains that type
  • reflecting GetCustomAttribute(typeof(ConfigurationPropertyAttribute)) on the consumer property throws TypeLoadException
  • ConfigProperty.ScanAssembliesForConfigPropertyHosts(...) now skips that foreign property and continues scanning later assemblies

That matches the downstream MemberNotNullWhenAttribute failure we were seeing from loaded test-platform assemblies, but reduces it to a deterministic upstream test.

Validation

  • dotnet restore
  • dotnet build --no-restore
  • dotnet test --project Tests/UnitTests.NonParallelizable/UnitTests.NonParallelizable.csproj --no-build -- --filter-class UnitTests.NonParallelizable.ConfigurationTests.ConfigPropertyAssemblyScanTests
  • dotnet test --project Tests/UnitTests.NonParallelizable/UnitTests.NonParallelizable.csproj --no-build -- --filter-namespace UnitTests.NonParallelizable.ConfigurationTests
  • dotnet test --project Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj --no-build -- --filter-namespace ConfigurationTests
  • dotnet test --project Tests/UnitTests.NonParallelizable/UnitTests.NonParallelizable.csproj --no-build
  • dotnet test --project Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj --no-build

@tig
tig merged commit 8c9f013 into tui-cs:develop May 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants