Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix MethodAccessException in nested configuration proxy types on Linux and macOS - #24

#24
Merged
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
Mar 13, 2026
Merged

Fix MethodAccessException in nested configuration proxy types on Linux and macOS#24
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 commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

On Linux and macOS, the CLR raises a MethodAccessException when a dynamically generated proxy type's constructor calls another proxy type's constructor — both defined as NotPublic within the same in-memory dynamic assembly.

Failing builds: #2022 · #2024 · #2026

System.MethodAccessException: Attempt by method
  'Dibix.Tests.TestConfiguration..ctor(ConfigurationInitializationToken)'
to access method
  'Dibix.Tests.NestedTestConfiguration..ctor(ConfigurationInitializationToken)' failed.

   at Dibix.Tests.TestConfiguration..ctor(ConfigurationInitializationToken)
   ...
   at Dibix.Testing.ConfigurationProxyBuilder.BuildProxyIfNeeded[T](ConfigurationInitializationToken initializationToken)
      in ConfigurationProxyBuilder.cs:line 27

Changes

  • ConfigurationProxyBuilder.cs — Use TypeAttributes.Public instead of TypeAttributes.NotPublic when emitting proxy types into the AssemblyBuilderAccess.Run assembly. 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 excluded Load_Lazy_AccessNotInitializedProperty_ThrowsDuringPropertyAccess from the macOS pipeline run. The filter and accompanying comments are no longer needed since the fix applies to all platforms. The arguments property 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_ThrowsDuringPropertyAccess sporadically fails on Linux Azure Pipeline agents with the following error:

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.

Root Cause

In src/Dibix.Testing/Configuration/ConfigurationProxyBuilder.cs at line 54, dynamically generated proxy types are created with TypeAttributes.NotPublic:

TypeBuilder typeBuilder = moduleBuilder.DefineType(type.FullName, attr: TypeAttributes.NotPublic | TypeAttributes.Sealed, parent: type);

When configuration classes have nested complex properties (e.g., TestConfiguration containing NestedTestConfiguration), 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 NotPublic to Public within the dynamic assembly. In the context of a dynamic assembly created with AssemblyBuilderAccess.Run, marking types as Public makes 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.cs

Line 54 - Change from:

TypeBuilder typeBuilder = moduleBuilder.DefineType(type.FullName, attr: TypeAttributes.NotPublic | TypeAttributes.Sealed, parent: type);

To:

TypeBuilder typeBuilder = moduleBuilder.DefineType(type.FullName, attr: TypeAttributes.Public | TypeAttributes.Sealed, parent: type);

Expected Outcome

After this change, dynamically generated proxy types will be able to instantiate each other without visibility issues, resolving the sporadic MethodAccessException on Linux Azure Pipeline agents.

References

  • Error occurs in: src/Dibix.Testing/Configuration/ConfigurationProxyBuilder.cs line 27
  • Stack trace shows the issue originates from nested proxy construction at line 161-162 where DefineComplexProperty emits IL to create nested proxy instances

The 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, Span1 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, Action1 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.

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
@C0nquistadore C0nquistadore reopened this Mar 12, 2026
@C0nquistadore

Copy link
Copy Markdown
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.

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

@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_Ac...

Done in 55f64be. Removed the test filter and stale comments, and collapsed arguments back to a single line for the macOS section, matching the Windows format.

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
C0nquistadore marked this pull request as ready for review March 12, 2026 14:47
@C0nquistadore
C0nquistadore force-pushed the copilot/fix-nested-property-access-exception branch from 55f64be to bca9337 Compare March 12, 2026 21:07
Copilot AI and others added 2 commits March 12, 2026 23:00
…namic assembly

Co-authored-by: C0nquistadore <16206104+C0nquistadore@users.noreply.github.com>
Co-authored-by: C0nquistadore <16206104+C0nquistadore@users.noreply.github.com>
Copilot AI and others added 2 commits March 12, 2026 23:00
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
C0nquistadore force-pushed the copilot/fix-nested-property-access-exception branch from bca9337 to 07b6ef8 Compare March 12, 2026 22:00
@C0nquistadore
C0nquistadore merged commit 0f0ab0e into main Mar 13, 2026
7 checks passed
@C0nquistadore
C0nquistadore deleted the copilot/fix-nested-property-access-exception branch March 13, 2026 05:31
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.