Skip to content

A DLL whose extension methods couldn't be read can be required again - #11

Closed
sholden wants to merge 1 commit into
fix/path-loaded-assembly-dependenciesfrom
fix/extension-scan-retry
Closed

sholden wants to merge 1 commit into
fix/path-loaded-assembly-dependenciesfrom
fix/extension-scan-retry

Conversation

@sholden

@sholden sholden commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

A DLL whose extension methods couldn't be read stayed that way for the rest of the process. #10 lists this under "Found, not fixed".

using_clr_extensions Demo
require '/x/Demo2.dll'   # LoadError: Demo, which Demo2 is built against, can't be found
require '/y/Demo.dll'
require '/x/Demo2.dll'   # true, but Demo2's extension methods are never read
w.shout                  # NoMethodError, though Demo::LaterExtensions.Shout(w) works

A worse variant shows up when the DLL is required before any extension methods are asked for. That require only queues the DLL and succeeds. The first using_clr_extensions or using reads the queue and raises from that line, whatever namespace it names:

require '/x/Demo2.dll'   # fine
using System::Linq       # Errno::ENOENT: Could not load file or assembly 'Demo, ...'

Every assembly queued after Demo2 also lost its extension methods for good. master has both problems. #10 makes them rarer, because a DLL now fails this way only when nothing satisfies its reference. It still happens when a dependency is really missing.

Cause

Reading an assembly's extension methods loads the types in their signatures, so it fails when one of them lives in an assembly that can't be found. RubyContext.AddExtensionAssembly records an assembly as handled before reading it, and kept the record when reading failed.

On a retried require, the DLR's ScriptDomainManager.LoadAssembly doesn't report an assembly it has already seen. Even if it did, RubyContext would have skipped the assembly as handled. For the queue, RubyContext empties the queue before reading it, and one exception ended the loop.

What changed

  • An assembly whose extension methods can't be read is taken back out of the handled set, so the next attempt reads it again.
  • When require loads a DLL the runtime has already seen, it asks the context for any reading still owed. The retry above reads Demo2's extension methods and returns true.
  • Reading the queue, or the assemblies of a namespace being activated, warns about an assembly it can't read and carries on with the rest. The using line no longer raises. The warning names the DLL and what's missing:
    t.rb:3: warning: extension methods of Demo2 not read: Could not load file or assembly 'Demo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
    
    That assembly is read again at the next using of its namespace or the next require of it.
  • A require whose extension methods can't be read still raises LoadError, as before. Only the using path changed from raising to warning. Raising there broke a using of an unrelated namespace, and the queue was already lost by then.
  • The constant version is now bumped even when reading fails, because the assembly's namespaces are loaded either way.

The DLL itself can't be unloaded, so after a failed require its namespaces stay visible. That was already the case.

Tests

  • Require_UnreadableExtensions1 makes a require fail, loads the missing dependency, and retries. The retry returns true and the extension method works.
  • Require_UnreadableExtensions2 queues an unreadable DLL ahead of a good one, then activates their namespace. It expects one warning, the good DLL's method working, and a second warning, not an exception, when the namespace is activated again.
  • Both fail without the change. The first gets NoMethodError for shout, and the second raises FileNotFoundException from the activation.
  • The tests use DLLs required by path find the DLLs they reference, loaded or alongside #10's fixture writer, which can now name the extension method.

Results:

CI passed all seven checks. IronRuby.Tests reported 0 failure lines on ubuntu and windows with both net8.0 and net10.0, and spec/language passed with 2935 examples and 0 failures on both.

Stack

  1. CLR extension methods reach a method group used before using_clr_extensions Largo/ironruby#43, merged, fixes stale CLR overloads after using_clr_extensions
  2. Refinements: only refined calls pay, and the JIT and OSR keep working Largo/ironruby#49 makes refinements cost nothing where they can't change a call
  3. using System::Linq: CLR extension methods scoped like C#'s using directive #3 scopes CLR extension methods with using
  4. DLLs required by path find the DLLs they reference, loaded or alongside #10 resolves the DLLs a DLL required by path references
  5. This PR, stacked on DLLs required by path find the DLLs they reference, loaded or alongside #10. It needs DLLs required by path find the DLLs they reference, loaded or alongside #10's commit, for the line in Loader.LoadFromPath it changes and for the test fixtures. With DLLs required by path find the DLLs they reference, loaded or alongside #10's commit it also applies to master.

🤖 Generated with Claude Code

Reading an assembly's extension methods loads the types in their
signatures, and fails if one lives in an assembly that can't be found.
RubyContext recorded the assembly as handled before reading it, and kept the
record when reading failed, so nothing ever tried again:

  using_clr_extensions Demo
  require '/x/Demo2.dll'   # LoadError: Demo can't be found
  require '/y/Demo.dll'
  require '/x/Demo2.dll'   # true, but Demo2's extension methods never read

The failed require left Demo2 out of $LOADED_FEATURES, as it should, but
the retry found the runtime had seen the assembly. The DLR's
ScriptDomainManager reports an assembly once, and RubyContext skipped it.

A DLL required before any extension methods were asked for was only queued,
and its require succeeded. The first using_clr_extensions or `using' read
the queue, raised the reading error from that line, whatever its namespace,
and had already emptied the queue: every assembly after the bad one lost
its extension methods for good.

Now an assembly whose extension methods can't be read is forgotten, so the
next attempt reads it again. A require of a DLL the runtime has seen asks
the context for any reading still owed, so the retry above reads Demo2's
extension methods and returns true. Reading the queue, or the assemblies of
a namespace being activated, warns about an assembly it can't read and goes
on with the rest:

  warning: extension methods of Demo2 not read: Could not load file or
  assembly 'Demo, Version=1.0.0.0, ...'

That assembly is read again at the next activation of its namespace or
require of it. The constant version is bumped even when reading fails, as
the assembly's namespaces are loaded either way.

Require_UnreadableExtensions1 retries a require that failed, and
Require_UnreadableExtensions2 queues an unreadable DLL ahead of a good one
and activates their namespace twice. Both fail without the change. The
fixture writer can now name the extension method.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant