microsoft / testfx

MSTest framework and adapter
MIT License
734 stars 254 forks source link

Common Language Runtime detected an invalid program #3937

Closed hyke123 closed 3 days ago

hyke123 commented 5 days ago

Describe the bug

I got the exception when I want to visit the image in ImageList

Steps To Reproduce

I get the exception "Common Language Runtime detected an invalid program" for this line: ImageList1.Images[0];

[TestMethod]
public void TestMethod1()
{
    ImageList ImageList1 = new ImageList();
    // Set the ImageSize property to a larger size 
    ImageList1.ImageSize = new Size(112, 112);
    // Add two images to the list.
    ImageList1.Images.Add(System.Drawing.Image.FromFile("C:\\inv2026\\x64\\INV\\Usr\\Pub\\Doc\\ADSK\\INV\\Tex\\car3.BMP"));
    ImageList1.Images.Add(System.Drawing.Image.FromFile("C:\\inv2026\\x64\\INV\\Usr\\Pub\\Doc\\ADSK\\INV\\Tex\\Millennium.bmp"));
    var tt = ImageList1.Images[0];
    Console.WriteLine("1");
}
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
    <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="6.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
    <PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
  </ItemGroup>

  <ItemGroup>
    <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
  </ItemGroup>

</Project>

Expected behavior

Actual behavior

Additional context

Image

Evangelink commented 3 days ago

I can reproduce the error only when using improper images but this is not linked to MSTest so I am going to close this issue.

hyke123 commented 3 days ago

Hi @Evangelink Thanks for you reply,Could you share me what's the "improper images". Could you give one example? Thanks.

hyke123 commented 3 days ago

The code can work fine in ConsoleApp(net8) project. It also work fine in UnitTest Framework project.

Evangelink commented 3 days ago

Can you share the 2 images you are using so that I can ensure there is a bug in MSTest?

hyke123 commented 3 days ago

@Evangelink Thanks for your help,I think I find the root cause,the root cause is we are using 3rd plugin:typeMock.