Repository navigation
Description
Description
Prior to dotnet-sdk-11.0.100-preview.4.26224.122, running "dotnet vstest DockerWatch.Test.dll" 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] GlobalToolsNETCore21Part02 execute "dotnet vstest" failed with error: System.TypeLoadException : Could not load type 'Microsoft.Extensions.Logging.Internal.FormattedLogValues'... · Issue #126995 · 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 Moq.MockException, as shown below:
Moq.MockException :
Expected invocation on the mock at least once, but was never performed: m => m.Log<Object>(LogLevel.Trace, It.IsAny<EventId>(), It.Is<FormattedLogValues>(v => v.ToString().Contains("trace")), It.IsAny<Exception>(), It.IsAny<Func<Object, Exception, String>>())
No setups configured.
Performed invocations:
ILogger.Log<FormattedLogValues>(LogLevel.Trace, 0, [[{OriginalFormat}, trace]], null, Func<FormattedLogValues, Exception, String>)
Stack Trace:
at Moq.Mock.VerifyCalls(Mock targetMock, InvocationShape expectation, LambdaExpression expression, Times times, String failMessage)
at Moq.Mock.Verify[T](Mock`1 mock, Expression`1 expression, Times times, String failMessage)
at Moq.Mock`1.Verify(Expression`1 expression)
at DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogTraceMessages() in C:\Users\v-joyzhu\Desktop\unit test\docker-watch-master\docker-watch-master\test\DockerWatch.Test\LoggerAdapterTest.cs:line 63
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
More detailed information, please see the devdiv bug.
Reproduction Steps
Environment Configuration:
The machine has dotnet-sdk-11.0.0-preview.4.26224.122 installed.
- Copy GlobalToolsNETCore21Part02Test56 from shared server (see location from devdiv bug) to local machine.
- Modify DockerWatch.Test.runtimeconfig.json to enable the app to run on dotnet-sdk-11.0.0-preview.4.26224.122.
"framework": {
"name": "Microsoft.NETCore.App",
"version": "11.0.0-preview.4.26224.122"
}
Repro Steps:
- Open cmd in GlobalToolsNETCore21Part02Test56.
- Execute command: dotnet vstest DockerWatch.Test.dll.
Expected behavior
Passed! - Failed: 0, Passed: 18, Skipped: 0, Total: 18, Duration: 3 s - DockerWatch.Test.dll
Actual behavior
3 test cases failed with below error:
[xUnit.net 00:00:03.70] DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogTraceMessages [FAIL]
[xUnit.net 00:00:03.71] DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogAnErrorMessage [FAIL]
[xUnit.net 00:00:03.72] DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogAnInformationMessage [FAIL]
Failed DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogTraceMessages [94 ms]
Error Message:
Moq.MockException :
Expected invocation on the mock at least once, but was never performed: m => m.Log(LogLevel.Trace, It.IsAny(), It.Is(v => v.ToString().Contains("trace")), It.IsAny(), It.IsAny<Func<Object, Exception, String>>())
No setups configured.
Performed invocations:
ILogger.Log(LogLevel.Trace, 0, [[{OriginalFormat}, trace]], null, Func<FormattedLogValues, Exception, String>)
Stack Trace:
at Moq.Mock.VerifyCalls(Mock targetMock, InvocationShape expectation, LambdaExpression expression, Times times, String failMessage)
at Moq.Mock.Verify[T](Mock1 mock, Expression1 expression, Times times, String failMessage)
at Moq.Mock1.Verify(Expression1 expression)
at DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogTraceMessages() in C:\Users\v-joyzhu\Desktop\unit test\docker-watch-master\docker-watch-master\test\DockerWatch.Test\LoggerAdapterTest.cs:line 63
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Failed DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogAnErrorMessage [12 ms]
Error Message:
Moq.MockException :
Expected invocation on the mock at least once, but was never performed: m => m.Log(LogLevel.Error, It.IsAny(), It.Is(v => v.ToString().Contains("error")), It.IsAny(), It.IsAny<Func<Object, Exception, String>>())
No setups configured.
Performed invocations:
ILogger.Log(LogLevel.Error, 0, [[{OriginalFormat}, error]], null, Func<FormattedLogValues, Exception, String>)
Stack Trace:
at Moq.Mock.VerifyCalls(Mock targetMock, InvocationShape expectation, LambdaExpression expression, Times times, String failMessage)
at Moq.Mock.Verify[T](Mock1 mock, Expression1 expression, Times times, String failMessage)
at Moq.Mock1.Verify(Expression1 expression)
at DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogAnErrorMessage() in C:\Users\v-joyzhu\Desktop\unit test\docker-watch-master\docker-watch-master\test\DockerWatch.Test\LoggerAdapterTest.cs:line 43
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Failed DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogAnInformationMessage [8 ms]
Error Message:
Moq.MockException :
Expected invocation on the mock at least once, but was never performed: m => m.Log(LogLevel.Information, It.IsAny(), It.Is(v => v.ToString().Contains("information")), It.IsAny(), It.IsAny<Func<Object, Exception, String>>())
No setups configured.
Performed invocations:
ILogger.Log(LogLevel.Information, 0, [[{OriginalFormat}, information]], null, Func<FormattedLogValues, Exception, String>)
Stack Trace:
at Moq.Mock.VerifyCalls(Mock targetMock, InvocationShape expectation, LambdaExpression expression, Times times, String failMessage)
at Moq.Mock.Verify[T](Mock1 mock, Expression1 expression, Times times, String failMessage)
at Moq.Mock1.Verify(Expression1 expression)
at DockerWatch.Test.LoggerAdapterTest.LogInformation_ShouldLogAnInformationMessage() in C:\Users\v-joyzhu\Desktop\unit test\docker-watch-master\docker-watch-master\test\DockerWatch.Test\LoggerAdapterTest.cs:line 23
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Failed! - Failed: 3, Passed: 15, Skipped: 0, Total: 18, Duration: 3 s - DockerWatch.Test.dll (netcoreapp2.1)
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 Moq.MockException)
Known Workarounds
No response
Configuration
Application Name: GlobalToolsNETCore21Part02
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-logging
See info in area-owners.md if you want to be subscribed.
MihuBot commentedon Apr 28, 2026
I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):
WeiweiCaiAcpt commentedon Apr 28, 2026
@ericstj Could you please take a look at this bug? The previous System.TypeLoadException is no longer occurring, but a new Moq.MockException appears in the latest build (11.0.100-preview.4.26224.122).
Also, could you please confirm whether this is a blocker for .NET 11 P4 validation? Thanks.
cincuranet commentedon Apr 28, 2026
AI Analysis
Context
This is the follow-up to #126995 (closed by PR #127194, which restored an obsolete shim
Microsoft.Extensions.Logging.Internal.FormattedLogValuesinMicrosoft.Extensions.Logging.Abstractions). With that shim in place, the originalTypeLoadExceptionno longer occurs — the test app (docker-watchLoggerAdapterTest) now actually runs to theVerifystep, where Moq reports the expectedm.Log(...)call was never observed.Root cause (this issue is not a runtime regression)
The test was authored against
Microsoft.Extensions.Loggingv2.x. Its mock setup looks like the well-known Moq pattern:ILogger.Log<TState>is a generic method. Each uniqueTStateproduces a distinct method instantiation at runtime, and Moq'sVerifymatches on that exact instantiation.PR #127194 added
Microsoft.Extensions.Logging.Internal.FormattedLogValuesback as an[Obsolete(error: true)] [EditorBrowsable(Never)]shim — a different CLR type from the modernMicrosoft.Extensions.Logging.FormattedLogValuesthatLoggerExtensions.LogInformationactually instantiates internally. So:LoggerExtensions.LogInformation(...)callslogger.Log<Microsoft.Extensions.Logging.FormattedLogValues>(...)— the new namespacelogger.Log<Microsoft.Extensions.Logging.Internal.FormattedLogValues>(...)TState⇒ different generic method instantiation ⇒ Moq sees zero matching invocations ⇒MockExceptionThis is the canonical "mocking
ILoggeris fragile" problem — exactly the topic linked by MihuBot: dotnet/extensions#1319. It's not unique to .NET 11; it's a long-standing consequence ofFormattedLogValueshaving been internalized in 3.0 (and was the very reason to mark these obsolete shim typeserror: truein PR #127194).Why the runtime can't round-trip this
Restoring the shim cannot make it bind-equivalent to the modern type:
…Internal.FormattedLogValuesand…FormattedLogValues.LoggerExtensionsto use the obsolete shim type internally would resurrect a public-but-obsolete type as a permanent ABI fixture in the modern code path — directly contradicting the intent of PR Add obsolete compatibility shims for moved Microsoft.Extensions.Logging internal types #127194 and the deprecation done years ago.Recommendation
Moq+ILoggeranti-pattern. Recommended fix lives in test code, not the runtime.It.IsAnyTypeand stop depending on the internalFormattedLogValuesidentity:Microsoft.Extensions.Logging.Testing.FakeLogger(inMicrosoft.Extensions.Diagnostics.Testing) instead of mockingILogger.ericstj commentedon Apr 28, 2026
Agree with @cincuranet's analysis and recommendation. We can restore the old types, but we won't make the runtime use them, nor would we ever "promise" to keep that the same.
This is not a blocker.
WeiweiCaiAcpt commentedon Apr 29, 2026
@ericstj Is this issue also caused by this breaking change ?
ericstj commentedon Apr 29, 2026
This issue is caused by this breaking change from 7 years ago -- dotnet/extensions#1319. It's observed when the tests are forced to run on net11 which updates the long-unsupported packages used by those tests to the latest version. I did some work to try to smooth over some of those breaks, but I cannot smooth this one over. In this case if someone cares about running the tests in this abandoned/archived respository they will need to update those tests as @cincuranet suggests.
If we have any repo in active development (and likely to actually retarget to net11) they are unlikely to be referencing these very old packages. I can measure this by looking at the usages of this type across a number of repos / internally.
ericstj commentedon Apr 29, 2026
FormattedLogValues Breaking Change Impact Analysis
Issue: dotnet/runtime#127496
Change:
Microsoft.Extensions.Logging.Internal.FormattedLogValueswas made internalDate: 2026-04-29
Search Methodology
GitHub code search:
FormattedLogValues Microsoft.Extensions.Logging.Internalexcluding source files, docs, and metadata (XML docs, API diffs, checked-in bin/packages, .txt/.md/.xml/.java dumps).Total code results (excluding docs/metadata): ~124 hits across GitHub
Category Breakdown
Production Source Analysis (deep-dive on 13 files)
Runtime Break — expects FormattedLogValues from framework callbacks (2 repos)
These cast/check the
stateparameter inILogger.Log()callbacks. Since the framework no longer passesFormattedLogValuesasstate, the cast returns null or the type check fails at runtime — even without recompilation.Recompile-only Break — constructs FormattedLogValues directly (4 repos)
These create
new FormattedLogValues(...)themselves. Since the type was brought back as obsolete, existing binaries continue to work. Only breaks when recompiled (obsolete error).Would NOT Break (4 repos - comment only)
Inaccessible (microsoft/msrecruit-scheduling-engine, Azure/azure-functions-rabbitmq-extension)
SAML-protected; could not fetch.
Test File Analysis
The 80 test hits follow a common pattern:
It.IsAny<FormattedLogValues>()inlogger.Verify(m => m.Log(...))FormattedLogValuesas thestateparameterNotable Test Repos
NuGet Package Analysis
Of the ~34 unique production source repos, 8 publish NuGet packages. None would affect applications targeting .NET 11:
as FormattedLogValuesKey observations:
Key Findings
1. Framework Targeting Supports "Won't Upgrade" Theory
Every production repo checked targets old frameworks:
netstandard2.0(most common)netcoreapp2.0,netcoreapp2.1net461None target net6.0+ or any modern TFM. These projects are built against the era when FormattedLogValues was public and would not be upgrading to .NET 11.
2. Predominantly Tests (65% of code hits)
The most common usage is in test code verifying
ILogger.Log()calls via Moq, matchingIt.IsAny<FormattedLogValues>(). This is exactly the pattern reported in #127496.3. Production Usage Is Custom Logger Adapters
The production code using FormattedLogValues is almost exclusively:
ILoggerimplementations that caststatetoFormattedLogValuesConclusion
Note: The type was brought back as obsolete, so binary compatibility is maintained. Existing binaries referencing
FormattedLogValuesstill compile and load. The actual runtime break is behavioral: the framework no longer usesFormattedLogValuesas thestateinILogger.Log()callbacks.The runtime impact is very low for anyone actually upgrading to .NET 11:
It.IsAny<FormattedLogValues>()that will fail at runtime (the exact scenario from [11.0.100-preview.4.26224.122] GlobalToolsNETCore21Part02 execute "dotnet vstest" failed with “Moq.MockException : Expected invocation on the mock at least once, but was never performed” #127496)statetoFormattedLogValues) — both target netstandard2.0 with old deps and haven't been updated since 2022FormattedLogValuesdirectly — these only break on recompile (obsolete error), not at runtimeThis strongly supports the theory that the people most likely to encounter this breakage are not actually updating to new frameworks, and the usage is predominantly in test code.