Fix MethodAccessException in nested configuration proxy types on Linux and macOS - #24
#24Merged
C0nquistadore merged 4 commits intoMar 13, 2026
mainServiceware/Dibix:mainfrom
copilot/fix-nested-property-access-exceptionServiceware/Dibix:copilot/fix-nested-property-access-exceptionCopy head branch name to clipboard
Merged
Fix MethodAccessException in nested configuration proxy types on Linux and macOS#24C0nquistadore merged 4 commits intomainServiceware/Dibix:mainfrom copilot/fix-nested-property-access-exceptionServiceware/Dibix:copilot/fix-nested-property-access-exceptionCopy head branch name to clipboard
C0nquistadore merged 4 commits into
mainServiceware/Dibix:mainfrom
copilot/fix-nested-property-access-exceptionServiceware/Dibix:copilot/fix-nested-property-access-exceptionCopy head branch name to clipboard
Conversation
Copilot
AI
changed the title
[WIP] Fix access exception for nested configuration properties
Fix sporadic MethodAccessException in nested configuration proxy types on Linux
Mar 12, 2026
Copilot
AI
changed the title
Fix sporadic MethodAccessException in nested configuration proxy types on Linux
Fix MethodAccessException in nested configuration proxy types on Linux
Mar 12, 2026
Copilot
AI
changed the title
Fix MethodAccessException in nested configuration proxy types on Linux
Restore Azure DevOps build links in PR description
Mar 12, 2026
Copilot
AI
changed the title
Restore Azure DevOps build links in PR description
Fix MethodAccessException in nested configuration proxy types on Linux
Mar 12, 2026
Collaborator
|
@copilot Initially it failed on macOS Azure Pipelines agent and then it was assumed that this is a macOS specific issue. Since It's not, the test ignore filter for test 'Load_Lazy_AccessNotInitializedProperty_ThrowsDuringPropertyAccess' can be safely removed. Bring the arguments property back to one line as it is already done for the other operating system platforms. |
Contributor
Author
Done in 55f64be. Removed the test filter and stale comments, and collapsed |
Copilot
AI
changed the title
Fix MethodAccessException in nested configuration proxy types on Linux
Fix MethodAccessException in nested configuration proxy types on Linux and macOS
Mar 12, 2026
C0nquistadore
marked this pull request as ready for review
March 12, 2026 14:47
C0nquistadore
approved these changes
Mar 12, 2026
C0nquistadore
force-pushed
the
copilot/fix-nested-property-access-exception
branch
from
March 12, 2026 21:07
55f64be to
bca9337
Compare
…namic assembly Co-authored-by: C0nquistadore <16206104+C0nquistadore@users.noreply.github.com>
Co-authored-by: C0nquistadore <16206104+C0nquistadore@users.noreply.github.com>
Co-authored-by: C0nquistadore <16206104+C0nquistadore@users.noreply.github.com>
…esolves the issue on all platforms Co-authored-by: C0nquistadore <16206104+C0nquistadore@users.noreply.github.com>
C0nquistadore
force-pushed
the
copilot/fix-nested-property-access-exception
branch
from
March 12, 2026 22:00
bca9337 to
07b6ef8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux and macOS, the CLR raises a
MethodAccessExceptionwhen a dynamically generated proxy type's constructor calls another proxy type's constructor — both defined asNotPublicwithin the same in-memory dynamic assembly.Failing builds: #2022 · #2024 · #2026
Changes
ConfigurationProxyBuilder.cs— UseTypeAttributes.Publicinstead ofTypeAttributes.NotPublicwhen emitting proxy types into theAssemblyBuilderAccess.Runassembly. This satisfies the stricter cross-type visibility rules the Linux/macOS CLR enforces within dynamic assemblies, while having no external exposure effect on an in-memory-only assembly.build/azure-pipelines-template/test.yml— Removed the macOS-specific test filter that excludedLoad_Lazy_AccessNotInitializedProperty_ThrowsDuringPropertyAccessfrom the macOS pipeline run. The filter and accompanying comments are no longer needed since the fix applies to all platforms. Theargumentsproperty for the macOS section is restored to a single-line format consistent with the other OS sections.Original prompt
Problem
The test
Dibix.Tests.TestConfigurationLoaderTests.Load_Lazy_AccessNotInitializedProperty_ThrowsDuringPropertyAccesssporadically fails on Linux Azure Pipeline agents with the following error:Root Cause
In
src/Dibix.Testing/Configuration/ConfigurationProxyBuilder.csat line 54, dynamically generated proxy types are created withTypeAttributes.NotPublic:When configuration classes have nested complex properties (e.g.,
TestConfigurationcontainingNestedTestConfiguration), both proxy types are marked as non-public. When the outer proxy's constructor tries to instantiate the inner proxy constructor, the CLR enforces accessibility rules and fails because a non-public type cannot access another non-public type's constructor in different scopes.This manifests sporadically on Linux due to timing/JIT compilation differences in how the CLR handles visibility rules for dynamically generated assemblies.
Solution
Change the generated proxy types from
NotPublictoPublicwithin the dynamic assembly. In the context of a dynamic assembly created withAssemblyBuilderAccess.Run, marking types asPublicmakes them accessible to each other within that dynamic assembly context, while still being contained and not exposed outside.File to modify:
src/Dibix.Testing/Configuration/ConfigurationProxyBuilder.csLine 54 - Change from:
To:
Expected Outcome
After this change, dynamically generated proxy types will be able to instantiate each other without visibility issues, resolving the sporadic
MethodAccessExceptionon Linux Azure Pipeline agents.References
src/Dibix.Testing/Configuration/ConfigurationProxyBuilder.csline 27DefineComplexPropertyemits IL to create nested proxy instancesThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: This happens sporadically on linux Azure pipelines agents
Test method Dibix.Tests.TestConfigurationLoaderTests.Load_Lazy_AccessNotInitializedProperty_ThrowsDuringPropertyAccess threw exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MethodAccessException: Attempt by method 'Dibix.Tests.TestConfiguration..ctor(Dibix.Testing.ConfigurationInitializationToken)' to access method 'Dibix.Tests.NestedTestConfiguration..ctor(Dibix.Testing.ConfigurationInitializationToken)' failed.
at Dibix.Tests.TestConfiguration..ctor(ConfigurationInitializationToken)
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span
1 copyOfArgs, BindingFlags invokeAttr) --- End of inner exception stack trace --- at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr)at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at Dibix.Testing.ConfigurationProxyBuilder.BuildProxyIfNeeded[T](ConfigurationInitializationToken initializationToken) in /home/vsts/work/1/s/src/Dibix.Testing/Configuration/ConfigurationProxyBuilder.cs:line 27
at Dibix.Testing.TestConfigurationLoader.BindConfigurationInstanceWithLazyValidation[T](IConfiguration configuration, TestContext testContext, Action
1 initializationAction) in /home/vsts/work/1/s/src/Dibix.Testing/Configuration/TestConfigurationLoader.cs:line 46 at Dibix.Testing.TestConfigurationLoader.BindConfigurationInstance[T](IConfiguration configuration, TestContext testContext, TestConfigurationValidationBehavior validationBehavior, Action1 initializationAction) in /home/vsts/work/1/s/src/Dibix.Testing/Configuration...This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.