Description
Description
When run the unit test of the 3rd party application with the latest .NET 10 build, it failed with error: System.TypeLoadException : Method 'InvokeNew' in type 'Bunit.JSInterop.BunitJSRuntime' from assembly 'bunit' does not have an implementation
.
Reproduction Steps
App Repro Steps:
- Change the App\Blog1.LinkDotNet.Blog.UnitTests.runtimeconfig.json to let the app run against with dotnet-sdk-10.0.100-preview.4.25215.17.
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "10.0.0-preview.4.25211.19"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "10.0.0-preview.4.25212.2"
}
]
- Open cmd in App\Blog1.
- Run command:
dotnet vstest LinkDotNet.Blog.UnitTests.dll
Expected Result:
All cases passed.
Actual Result:
Some cases failed with error:
System.TypeLoadException : Method 'InvokeNew' in type 'Bunit.JSInterop.BunitJSRuntime' from assembly 'bunit, Version=2.0.24.15694, Culture=neutral, PublicKeyToken=fe9c6306bcc1ce6f' does not have an implementation.
Stack Trace:
at Bunit.BunitJSInterop..ctor()
at Bunit.BunitJSInterop..ctor()
at Bunit.BunitContext..ctor() in /_/src/bunit/BunitContext.cs:line 30
at LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components.PatreonTests..ctor()
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
Minimal Repro Steps (Demo attached:Demo.zip):
- Create a default 9.0 ASP.NET Core Project and a default 9.0 xUnit Test Project. (The xUnit Test Project reference ASP.NET Core Project.)
- Install package bunit 2.0.36 in xUnit Test Project.
- Input the following code in UnitTest1.cs.
using Bunit;
namespace TestDemo
{
public class UnitTest1 : BunitContext
{
[Fact]
public void Test1()
{
}
}
}
- Build the xUnit Test Project.
- Change the runtimeconfig.json file to let the app run against with dotnet-sdk-10.0.100-preview.4.25215.17.
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "10.0.0-preview.4.25211.19"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "10.0.0-preview.4.25212.2"
}
]
- Run Test1 with command :
dotnet vstest TestDemo.dll
.
Expected behavior
Test1 Passed.
Actual behavior
Test1 Failed with error:
Message:
System.TypeLoadException : Method 'InvokeNew' in type 'Bunit.JSInterop.BunitJSRuntime' from assembly 'bunit, Version=2.0.36.26408, Culture=neutral, PublicKeyToken=fe9c6306bcc1ce6f' does not have an implementation.
Stack Trace:
BunitJSInterop.ctor()
BunitJSInterop.ctor()
BunitContext.ctor()
UnitTest1.ctor()
RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
Regression?
Yes
Verify Scenarios:
1). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.104: Pass
2). Windows 10 21H2 AMD64 + dotnet-sdk-10.0.100-preview.3.25201.16: Pass
3). Windows 10 21H2 AMD64 + dotnet-sdk-10.0.100-preview.4.25211.22: Fail
4). Windows 10 21H2 AMD64 + dotnet-sdk-10.0.100-preview.4.25215.17: Fail
Known Workarounds
No response
Configuration
Application Name: Blog1
OS: Windows 10 21H2
CPU: X64
.NET Build Number: dotnet-sdk-10.0.100-preview.4.25215.17
App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2449783
Github Link: https://github.com/linkdotnet/Blog
Other information
Findings:
In the demo, if xUnit Test Project does not reference ASP.NET Core Project, the error will not repro.
@dotnet-actwx-bot @dotnet/compat