Repository navigation
Description
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.
- Open command prompt.
- Input install command: "dotnet tool install --global NukedBit.NRepo".
- Press keyboard ‘Enter’.
- Verify: it install successfully.
- 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.
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
dotnet-policy-service commentedon Apr 28, 2026
Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.
Junjun-zhao commentedon Apr 28, 2026
Hi @ericstj Could you please take a look at this bug? The previous
System.TypeLoadExceptionerror 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.
cincuranet commentedon Apr 28, 2026
AI Analysis
Context
This is the direct sequel to #126994 (closed by PR #127188 — the DIM fix on
IHostBuilder.UseServiceProviderFactory). WithDOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2, theNukedBit.NRepoglobal tool (compiled againstMicrosoft.Extensions.Hosting v2.2.0.0) now gets past the previousTypeLoadExceptionand runs further — until it hits the next compatibility wall.New failure
Root cause
The same v3.0 breaking change (dotnet/extensions#637) that motivated #127188 also retyped:
The old assembly's
HostBuilder.CreateHostBuilderContextIL emits acallvirt … set_HostingEnvironment(class IHostingEnvironment). On the in-box .NET 11HostBuilderContext, onlyset_HostingEnvironment(IHostEnvironment)exists →MissingMethodException.IHostingEnvironmentitself is still present inMicrosoft.Extensions.Hosting.Abstractions(marked[Obsolete]) and inherits fromIHostEnvironment, 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 becauseHostBuilderContextis a concrete class, not an interface.Possible remediation paths
HostBuilderContext— a method literally namedset_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.ilsource file (similar tricks exist elsewhere in the runtime), guarded by#if NET. Reference assembly stays unchanged.get_HostingEnvironment()returningIHostingEnvironment— the tool may read the property next; pre-empt the next bug. Same IL-only approach.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
area-Extensions-Hosting, label needs to come offuntriaged.HostBuilderContextmirroring the philosophy of PR Fix System.TypeLoadException in NukedBit.NRepo global tool #127188 (preserve binary compat for oldMicrosoft.Extensions.Hostingconsumers), plus tests that load a synthetic v2.2-shapedHostBuilderContextconsumer to assert noMissingMethodExceptionis raised.HostBuilder/HostBuilderContextfor any other members whose signatures changed in the same v3.0 breaking change (e.g.,IHostingEnvironment-typed parameters/returns elsewhere).ericstj commentedon Apr 28, 2026
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).It does not inherit from
IHostEnvironment. It's a copy of the interface. Even if it did (eitherIHostingEnvironment : IHostEnvironmentorIHostEnvironment : IHostingEnvironment) it still would not help as the runtime is strict in type binding for methods. IOW, even ifIHostingEnvironmentis anIHostEnvironmentthe runtime will still throwMissingMethodExceptionwhen trying to bind a reference toset_HostingEnvironment(IHostingEnvironment value)when the definition isset_HostingEnvironment(IHostEnvironment value). Even ifIHostEnvironementis anIHostingEnvironmentthe runtime will fail to bind a reference toIHostingEnvironment get_HostingEnvironment()when the definition isIHostEnvironment 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
So a method or property overloaded on return type is not CLS-compliant, but maybe still permitted...
Also mentioned in I.10.2 Overloading
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#:
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
HostBuilderhttps://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
IHostingEnvironmentwith the property (expected) - but surprisingly C# still permits use both the get_ and set_ methods and chooses theIHostingEnvironmentversions. 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: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:
I can force it to run on 11 by editing it's runtimeconfig -- presumably users could do the same with
--allow-roll-forwardonce 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 theMissingMethodExceptionbut then it hits: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.Hostingpackage. We can't undo all these breaking changes to let the app run with this ancient copy ofMicrosoft.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.