Skip to content

3.11.0 fails on vstest.console.exe but works in visual studio 2022/insider #6676

Closed

Description

@Epicycle23

.NET Framework 4.8

After updating the nuget packages to 3.11.0 tests seem to run in different appdomains/contexts but only when using vstest.console.exe.
If running the tests in visual studio everything is fine.

Symptoms:

  • Tests with shared variables are crashing (after further analysis the actual issue seems to be also related to type resolving in a different context/appdomain)
  • Tests that load types via reflection fail e.g. TypeA is different from TypeA (apparently loaded in another context)

With 3.9.3 everything works as expected.

Looking at the fusion logs I can see warnings like this, for the assembly where the tests are located in:

WRN: The same assembly was loaded into multiple contexts of an application domain:...

Again, switching to 3.9.3 these warnings are gone and the binder log entry looks exactly the same (excluding the warnings at the end)

I tried to reproduce it with a simple solution but there everything works so I assume there is something wrong with project/solution but since it all works in 3.9.3 I wonder what the difference might be between those 2 versions and what would cause the newer version to behave differently.

Activity

  1. nohwnd commented on Oct 6, 2025

    @nohwnd
    Member

    but only when using vstest.console.exe.

    Is this as opposed to running with MTP?

    Can you share the project, runsettings and other "generic" parts of the project that are not showing any company secrets?

  2. nohwnd commented on Oct 6, 2025

    @nohwnd
    Member

    If running the tests in visual studio everything is fine.

    I cannot read, sorry.

  3. Epicycle23 commented on Oct 6, 2025

    @Epicycle23
    Author

    but only when using vstest.console.exe.

    Is this as opposed to running with MTP?

    Can you share the project, runsettings and other "generic" parts of the project that are not showing any company secrets?

    Unfortunately I am not able to share the project.
    No runsettings used.

    I can maybe go into detail what exactly is failing:

    • Setting a shared/static variable on TestInitialize, is null when accessing it inside a test method of that test class
    • Activator.CreateInstance(Type.GetType("Assembly.Of.TypeA.TypeA, Assembly.Of.TypeA")) returns an instance of TypeA but when asserting the expected type "TypeA" it fails because TypeA is different from TypeA (I assume it's loaded in another context from what I can see in the logs e.g. warnings and multiple appdomain ids)
  4. Epicycle23 commented on Oct 6, 2025

    @Epicycle23
    Author

    The statement about the static/shared variables was wrong/a misinterpretation of the error message I am seeing, in reality it seems to be another issue with type resolving, my bad.

  5. nohwnd commented on Oct 6, 2025

    @nohwnd
    Member

    thanks, that sounds like 2 symptoms of the same problem. I am trying to repro, but I don't see it reproduce. Nor can I think about situation where this would happen. Because we don't isolate tests within class into separate appdomains.

    What is different when running in vstest.console and in visual studio, is that vstest.console allows shared mode for dlls, which will allow multiple test assemblies to be loaded into the same process and run isolated in their own appdomains.

    I'd try to add /inisolation to your commandline run, to see if you will see different result. In VS you always run inIsolation.

  6. nohwnd commented on Oct 6, 2025

    @nohwnd
    Member

    in light of the last comment:

    I'd try to add /inisolation to your commandline run, to see if you will see different result. In VS you always run inIsolation.

    This is still true, that should have you in good state in both VS and commandline. If it does, then we need to see if the warning really is not there before as well. and if we are getting the same behavior.

  7. Epicycle23 commented on Oct 6, 2025

    @Epicycle23
    Author

    I already tried to run it with /inisolation but it didn't make a difference.

  8. Epicycle23 commented on Oct 6, 2025

    @Epicycle23
    Author

    More detail about what's happening with 3.11.0:

    Assemblies are loaded from 2 different locations:

    • OUT folder of the test deployment location (context: Default)
    • bin folder of the project (context: LoadFrom)

    Still completely confused why that only happens with 3.11.0 but not with 3.9.3

  9. nohwnd commented on Oct 6, 2025

    @nohwnd
    Member

    Do you use the deploy attribute on some of the tests? Maybe that is what is missing in my wannabe repro.

  10. Epicycle23 commented on Oct 6, 2025

    @Epicycle23
    Author

    Yes, the DeploymentItem attribute is used on some tests.

  11. nohwnd commented on Oct 10, 2025

    @nohwnd
    Member

    Please follow up in #6713 we think that is caused by the same problem in MSTest code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/deployment-item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions