Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unloading and Loading DirectRunner causes crash #522

Open
CharliePoole opened this issue Jan 3, 2019 · 2 comments
Open

Unloading and Loading DirectRunner causes crash #522

CharliePoole opened this issue Jan 3, 2019 · 2 comments
Labels
Bug Needs Confirmation V4 All issues related to V4 - use -label:V4 to get non-V4 issues
Milestone

Comments

@CharliePoole
Copy link
Member

I discovered this while experimenting various ways to handle reloading assemblies in the GUI. The engine supports two approaches: (1) Reload and (2) Unload followed by Load.

If you do an Unload and then Load the same assembly, the calls are allowed. In the case of tests being run in a separate process it works. But if the tests are in the same process an exception is thrown because of trying to access an unloaded AppDomain.

Looking at the code, I think it is because the AppDomain is created in LoadPackage and unloaded in UnloadPackage. However, the creation in LoadPackage is conditioned on no package being already loaded.

In principle, the various runners could work either way. That is, they could allow reuse or not allow it at all. But whichever is chosen, the runners should all work the same regardless of whether the tests are being run in or out of process.

For my own project I'm now trying a different approach but I think this should be fixed.

@ChrisMaddock
Copy link
Member

This sounds similar to #325 - which is fixed in the latest framework master, but not in a release yet. What do you think @CharliePoole - worth trying?

If it is that, I wonder if we can come up with some sort of workaround for the engine too. I'm not sure if it'll be possible. 🤔

@CharliePoole
Copy link
Member Author

@ChrisMaddock This is similar but I think it's a somewhat different issue. The engine actually gets rid of the domain itself when you call Unload. That makes the domain runner unusable but there are still references to it.

It looks like the engine Reload call does what I want - at first I didn't think it was working. So there is really no reason to unload and then load the runner with the same files. I think a good error message would do the job here. Then if problems come up with Reload - because we have never really exercised it with the console runner - we can fix them.

Basically, when you get a runner from the engine for a testpackage, an entire structure of subordinate runners is created that match the contents of the package. If you were allowed to reuse a runner once it was unloaded, then you might give it a completely different test package that didn't map to the pre-existing runner hierarchy at all! So I think that a runner, once unloaded, has to be unusable. Maybe we should dispose of it at that point and rely on the .NET message from usiing a disposed object.

@CharliePoole CharliePoole added this to the 4.0 milestone Mar 9, 2022
@CharliePoole CharliePoole added the V4 All issues related to V4 - use -label:V4 to get non-V4 issues label Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Confirmation V4 All issues related to V4 - use -label:V4 to get non-V4 issues
Projects
None yet
Development

No branches or pull requests

2 participants