Skip to content

[11.0.100-preview.4.26224.122] GlobalToolsNETCore22 throws System.MissingMethodException when running nrepo -n:newrepo #127495

Closed as not planned

Description

@WeiweiCaiAcpt

Description

Prior to dotnet-sdk-11.0.100-preview.4.26224.122, installing the NukedBit.NRepo global tool and running the command nrepo -n:newrepo resulted in a System.TypeLoadException when using dotnet-sdk-11.0.100-preview.4.26210.111 and dotnet-sdk-11.0.100-preview.4.26214.103. (refer to [dotnet-sdk-11.0.100-preview.4.26214.103] GlobalToolsNETCore22 throws System.TypeLoadException when running nrepo -n:newrepo · Issue #126994 · dotnet/runtime)
Starting from dotnet-sdk-11.0.100-preview.4.26224.122, the System.TypeLoadException no longer occurs; however, it is replaced by a new System.MissingMethodException, as shown below:

Unhandled exception. System.MissingMethodException: Method not found: 'Void Microsoft.Extensions.Hosting.HostBuilderContext.set_HostingEnvironment(Microsoft.Extensions.Hosting.IHostingEnvironment)'.

More detailed information, please see devdiv bug.

Reproduction Steps

Only dotnet-sdk-11.0.100-preview.4.26224.122 installed on machine and DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX = 2 environment variable was set.

  1. Open command prompt.
  2. Input install command: "dotnet tool install --global NukedBit.NRepo".
  3. Press keyboard ‘Enter’.
  4. Verify: it install successfully.
  5. Input “set NREPO_GITHUB_TOKEN=(input your github token)”.
    6.Press keyboard “Enter”
    7.Input “nrepo -n:newrepo”
    8.Press keyboard “Enter””

Expected behavior

Execute successfully.

Actual behavior

Running "nrepo -n:newrepo" with an unhandled exception:
Unhandled exception. System.MissingMethodException: Method not found: 'Void Microsoft.Extensions.Hosting.HostBuilderContext.set_HostingEnvironment(Microsoft.Extensions.Hosting.IHostingEnvironment)'.
at Microsoft.Extensions.Hosting.HostBuilder.CreateHostBuilderContext()
at Microsoft.Extensions.Hosting.HostBuilder.CreateHostBuilderContext()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Microsoft.Extensions.Hosting.HostBuilderExtensions.RunCommandLineApplicationAsync[TApp](IHostBuilder hostBuilder, String[] args, CancellationToken cancellationToken)
at NukedBit.NRepo.Program.Main(String[] args) in d:\a\1\s\src\NukedBit.NRepo\Program.cs:line 18
at NukedBit.NRepo.Program.

(String[] args)
at System.Environment.CallEntryPoint(IntPtr entryPoint, String[]* pArgument, Int32* pReturnValue, Boolean captureException, Exception* pException)

Regression?

Yes

Verify Scenarios:
1). Windows 11 24H2 AMD64 + dotnet-sdk-11.0.100-preview.3.26207.106: Pass
2). Windows 11 24H2 AMD64 + dotnet-sdk-11.0.100-preview.4.26210.111: Fail (failed with System.TypeLoadException)
3). Windows 11 24H2 AMD64 + dotnet-sdk-11.0.100-preview.4.26214.103: Fail (failed with System.TypeLoadException)
4). Windows 11 24H2 AMD64 + dotnet-sdk-11.0.100-preview.4.26224.122: Fail (failed with System.MissingMethodException)

Known Workarounds

No response

Configuration

Application Name: GlobalToolsNETCore22
OS: Windows 11 25H2
CPU: X64
.NET Build Number: dotnet-sdk-11.0.100-preview.4.26224.122

dotnet --info

.NET SDK:
Version: 11.0.100-preview.4.26224.122
Commit: 48bd87d899
Workload version: 11.0.100-manifests.e88583fc
MSBuild version: 18.7.0-preview-26224-122+48bd87d89

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\11.0.100-preview.4.26224.122\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 11.0.0-preview.4.26224.122
Architecture: x64
Commit: 48bd87d899

.NET SDKs installed:
11.0.100-preview.4.26224.122 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 11.0.0-preview.4.26224.122 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 11.0.0-preview.4.26224.122 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 11.0.0-preview.4.26224.122 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other information

@dotnet-actwx-bot @dotnet/compat

Activity

  1. added
    untriaged
    on Apr 28, 2026
  2. dotnet-policy-service commented on Apr 28, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-extensions-hosting
    See info in area-owners.md if you want to be subscribed.

  3. Junjun-zhao commented on Apr 28, 2026

    @Junjun-zhao
    Member

    Hi @ericstj Could you please take a look at this bug? The previous System.TypeLoadException error has been resolved, but there is a new error on the latest build 11.0.100-preview.4.26224.122.

    In the meantime, could you please confirm if this is a blocker for .NET 11 P4 validation? Thanks.

  4. cincuranet commented on Apr 28, 2026

    @cincuranet
    Contributor

    AI Analysis

    Context

    This is the direct sequel to #126994 (closed by PR #127188 — the DIM fix on IHostBuilder.UseServiceProviderFactory). With DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2, the NukedBit.NRepo global tool (compiled against Microsoft.Extensions.Hosting v2.2.0.0) now gets past the previous TypeLoadException and runs further — until it hits the next compatibility wall.

    New failure

    MissingMethodException: Method not found:
    'Void Microsoft.Extensions.Hosting.HostBuilderContext.set_HostingEnvironment(IHostingEnvironment)'
       at Microsoft.Extensions.Hosting.HostBuilder.CreateHostBuilderContext()
    

    Root cause

    The same v3.0 breaking change (dotnet/extensions#637) that motivated #127188 also retyped:

    // v2.x (what NRepo's HostBuilder.dll IL still references):
    public IHostingEnvironment HostingEnvironment { get; set; }
    
    // .NET Core 3.0+ / current (HostBuilderContext.cs:29):
    public IHostEnvironment HostingEnvironment { get; set; }

    The old assembly's HostBuilder.CreateHostBuilderContext IL emits a callvirt … set_HostingEnvironment(class IHostingEnvironment). On the in-box .NET 11 HostBuilderContext, only set_HostingEnvironment(IHostEnvironment) exists → MissingMethodException.

    IHostingEnvironment itself is still present in Microsoft.Extensions.Hosting.Abstractions (marked [Obsolete]) and inherits from IHostEnvironment, so the type resolves; only the setter overload is missing.

    Why the previous fix doesn't cover this

    PR #127188 used a Default Interface Method on IHostBuilder. That trick is unavailable here because HostBuilderContext is a concrete class, not an interface.

    Possible remediation paths

    1. Add a compatibility setter overload on HostBuilderContext — a method literally named set_HostingEnvironment(IHostingEnvironment value) that forwards to the property. The CLR allows two methods with the same name and different signatures (the property setter is just [SpecialName] set_HostingEnvironment(IHostEnvironment)), but C# disallows declaring it directly. It must be authored in IL or via an .il source file (similar tricks exist elsewhere in the runtime), guarded by #if NET. Reference assembly stays unchanged.
    2. Also expose get_HostingEnvironment() returning IHostingEnvironment — the tool may read the property next; pre-empt the next bug. Same IL-only approach.
    3. Recommend tool republish — long-term, NRepo (and other tools targeting Microsoft.Extensions.Hosting 2.2.0) should be retargeted; .NET Core 2.x has been out of support for years. But this is the typical "don't break the world on roll-forward" scenario, so an in-box compat shim is the natural answer given the precedent of Fix System.TypeLoadException in NukedBit.NRepo global tool #127188.

    Recommendation

    • Triage as a known compat regression for .NET 11 P4, owner @ericstj, area area-Extensions-Hosting, label needs to come off untriaged.
    • The fix is a small IL-shim on HostBuilderContext mirroring the philosophy of PR Fix System.TypeLoadException in NukedBit.NRepo global tool #127188 (preserve binary compat for old Microsoft.Extensions.Hosting consumers), plus tests that load a synthetic v2.2-shaped HostBuilderContext consumer to assert no MissingMethodException is raised.
    • Worth also auditing HostBuilder / HostBuilderContext for any other members whose signatures changed in the same v3.0 breaking change (e.g., IHostingEnvironment-typed parameters/returns elsewhere).
  5. removed
    untriaged
    on Apr 28, 2026
  6. ericstj commented on Apr 28, 2026

    @ericstj
    Member

    I previously looked at this and included it as known in the docs. Apps hitting it need to rebuild against a 3.1 or later Hosting.Abstractions -- or update their reference to Microsoft.Extensions.Hosting (if that's the source of the references to HostBuilderContext).

    IHostingEnvironment itself is still present in Microsoft.Extensions.Hosting.Abstractions (marked [Obsolete]) and inherits from IHostEnvironment

    It does not inherit from IHostEnvironment. It's a copy of the interface. Even if it did (either IHostingEnvironment : IHostEnvironment or IHostEnvironment : IHostingEnvironment) it still would not help as the runtime is strict in type binding for methods. IOW, even if IHostingEnvironment is an IHostEnvironment the runtime will still throw MissingMethodException when trying to bind a reference to set_HostingEnvironment(IHostingEnvironment value) when the definition is set_HostingEnvironment(IHostEnvironment value) . Even if IHostEnvironement is an IHostingEnvironment the runtime will fail to bind a reference to IHostingEnvironment get_HostingEnvironment() when the definition is IHostEnvironment get_HostingEnvironment(). There is no combination here that permits binary compatibility.

    @cincuranet proposes adding IL-only definitions of the legacy methods. One can imagine a these merged as IL, with the getter overloading on return value. We might be able to represent that in IL, but I'd be worried about side effects of shipping such IL that's not representable in C#.

    ECMA-335 states

    CLS Rule 38: Properties and methods can be overloaded based only on the number and types of their parameters, except the conversion operators named op_Implicit and op_Explicit, which can also be overloaded based on their return type.

    So a method or property overloaded on return type is not CLS-compliant, but maybe still permitted...

    Also mentioned in I.10.2 Overloading

    Following the rules of the CTS, it is possible for duplicate names to be defined in the same scope
    as long as they differ in either kind (field, method, etc.) or signature. The CLS imposes a stronger
    restriction for overloading methods. Within a single scope, a given name can refer to any number
    of methods provided they differ in any of the following:

    • Number of parameters
    • Type of any parameter
      Notice that the signature includes more information, but CLS-compliant languages need not
      produce or consume classes that differ only by that additional information (see Partition II
      for the complete list of information carried in a signature):
    • Calling convention
    • Custom modifiers
    • Return type
    • Whether a parameter is passed by value or by reference
      There is one exception to this rule. For the special names op_Implicit and op_Explicit,
      described in §I.10.3.3, methods can be provided that differ only by their return type. These are
      marked specially and can be ignored by compilers that don’t support operator overloading.
      Properties shall not be overloaded by type (that is, by the return type of their getter method),
      but they can be overloaded with different number or types of indices (that is, by the number and
      types of the parameters of their getter methods). The overloading rules for properties are
      identical to the method overloading rules.

    That Properties shall not be overloaded by type (that is, by the return type of their getter method), seems definitive that we shouldn't attempt to define a property in this way.

    Is there middle-ground hack for compat? Suppose we add the methods, but not the property metadata?? We'd be in that middle-ground grey area where we are using property conventions to define normal methods. I can see this a possible, but it may have practical breaks due to various tools / compilers / analyzers treat such methods.

    I did find that I could actually define the setter in C#:

        public static IHostEnvironment HostingEnvironment { get; set; }
        [Obsolete("Use the HostingEnvironment property instead.")]
        public static void set_HostingEnvironment(IHostingEnvironment env) { }

    Using such an assembly in an app that only ever sets the property works -- It could satisfy folks using just GenericHost who only ever hit this because of the usage in HostBuilder https://github.com/aspnet/Hosting/blob/1da228d28fdfcfb2d77241c4e0413efec1beeafd/src/Microsoft.Extensions.Hosting/HostBuilder.cs#L157. After all -- most of these concepts in IHostingEnvironment/IHostEnvironment are for web apps, and we don't expect any web apps to be hitting these cases (targeting only base shared framework).

    Attempting to define the get method results in CS0082: Type 'HostBuilderContext' already reserves a member called 'get_HostingEnvironment' with the same parameter types.
    I did find that I could produce such an assembly with ILAsm, and that resolves the runtime exceptions for an app calling the getter. Recompiling an app against this will fail if it tries to use IHostingEnvironment with the property (expected) - but surprisingly C# still permits use both the get_ and set_ methods and chooses the IHostingEnvironment versions. I also tested round-tripping the IL of the program and it works correctly, since the IL represents the return value in the function calls:

        IL_0000:  newobj     instance void MyHostingEnvironment::.ctor()
        IL_0005:  stloc.0
        IL_0006:  ldloc.0
        IL_0007:  call       void [lib]lib.Class1::set_HostingEnvironment(class [lib]lib.IHostingEnvironment)
        IL_000c:  nop
        IL_000d:  call       class [lib]lib.IHostingEnvironment [lib]lib.Class1::get_HostingEnvironment()
        IL_0012:  stloc.1
        IL_0013:  newobj     instance void MyHostEnvironment::.ctor()
        IL_0018:  call       void [lib]lib.Class1::set_HostingEnvironment(class [lib]lib.IHostEnvironment)
        IL_001d:  nop
        IL_001e:  call       class [lib]lib.IHostEnvironment [lib]lib.Class1::get_HostingEnvironment()
    

    I can think of other tools that might fail here -- for example tools that attempt to round trip as C# like https://github.com/[dotnet/source-build-assets](https://github.com/dotnet/source-build-assets), or tools that might assume properties for get_ set_, reflection callers, etc. Lots of unknowns.

    I took a closer look at the specific app involved here. https://github.com/nukedbit/nrepo https://github.com/nukedbit/nrepo. It seems to have some usage, but rather small (under 100 downloads in last couple months). I installed the tool and tried it -- it requires 2.2 and doesn't work with latest runtime out of the box:

    You must install or update .NET to run this application.
    App: C:\Users\ericstj.dotnet\tools\nrepo.exe
    Architecture: x64
    Framework: 'Microsoft.NETCore.App', version '2.2.0' (x64)

    I can force it to run on 11 by editing it's runtimeconfig -- presumably users could do the same with --allow-roll-forward once we ship 11 stable. I can reproduce the original report here. I then tried to apply my setter only fix. That did indeed cause the application to make it past the MissingMethodException but then it hits:

    Unhandled exception. System.InvalidOperationException: No service for type 'Microsoft.Extensions.Hosting.IHostApplicationLifetime' has been registered.
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
       at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
       at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.WaitForShutdownAsync(IHost host, CancellationToken token)
       at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
       at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
       at Microsoft.Extensions.Hosting.HostBuilderExtensions.RunCommandLineApplicationAsync[TApp](IHostBuilder hostBuilder, String[] args, CancellationToken cancellationToken)
       at NukedBit.NRepo.Program.Main(String[] args) in d:\a\1\s\src\NukedBit.NRepo\Program.cs:line 18
       at NukedBit.NRepo.Program.<Main>(String[] args)
    

    When shutting down. This is due to dotnet/extensions@6991e2b in 3.0 adding a dependency in WaitForShutdownAsync in an IHostApplicationLifetime being registered. This is a subtle functional break between assumptions made in the newer Hosting.Abstractions not being satisfied by the old Hosting.

    So really the best case fix for this is to update to a newer Microsoft.Extensions.Hosting package. We can't undo all these breaking changes to let the app run with this ancient copy of Microsoft.Extensions.Hosting. I was able to test that updating all the dependencies in this project to 3.1 fixes all issues and allows it to run on 11.0.

    We can wait and see if we hear more reports of this and re-evaluate the cost/risk vs compat tradeoff -- but right now my appetite for a hacky fix here is low, given it won't even fully unblock this application, which isn't seeing a lot of usage, and has a workaround.

  7. locked and limited conversation to collaborators on May 29, 2026
  8. added this to the 11.0.0 milestone on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions