Skip to content

[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

@WeiweiCaiAcpt

Description

@WeiweiCaiAcpt

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.

  1. Copy GlobalToolsNETCore21Part02Test56 from shared server (see location from devdiv bug) to local machine.
  2. 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:

  1. Open cmd in GlobalToolsNETCore21Part02Test56.
  2. 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

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions