selenium: [🐛 Bug]: OneTimeSetUp: System.IO.FileLoadException : Could not load file or assembly 'System.Text.Json, Version=8.0.0.0
What happened?
Ever since updating Selenium.WebDriver past 4.23.0, running integration tests fails on the OneTimeSetUp. To be clear, I can run my full integration test suite on 4.23.0, but I get the same setup failures on 4.24.0 and 4.25.0. For some reason it seems to still be looking for System.Text.Json, Version=8.0.0.0 even though the dependency requires 8.0.4. I notice that when trying to install 8.0.0 manually, it says there is a high severity vulnerability which is why I assume the update to require 8.0.4 exists.
Something is still stuck trying to download System.Text.Json 8.0.0 even after the update of the webdriver beyond 4.23.0
How can we reproduce the issue?
Install Selenium.WebDriver v4.25.0 and try to run integration test suite.
Relevant log output
Message:
OneTimeSetUp: System.IO.FileLoadException : Could not load file or assembly 'System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Stack Trace:
SeleniumManager.BinaryPaths(String arguments)
DriverFinder.BinaryPaths()
DriverFinder.GetDriverPath()
ChromiumDriver.GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
ChromiumDriver.ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
ChromeDriver.ctor(ChromeOptions options)
Setup.Init() line 42
Operating System
Windows 11
Selenium version
Selenium.WebDriver v4.25.0
What are the browser(s) and version(s) where you see this issue?
Chrome
What are the browser driver(s) and version(s) where you see this issue?
Selenium.WebDriver.ChromeDriver v129.0.6668.10000
Are you using Selenium Grid?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (9 by maintainers)
Yes, exactly. For those users targeting full framework, it will be necessary to ensure that they’re either placing the redirects manually or re-working their project files to automatically generate them.
I have run into a very similar error as originally reported, but, at least in my exact case, this does not appear to be directly related to the Selenium assembly or packaging. In my case, taking on
4.26.1(from a3.xversion) introduced the issue in the context of running some legacy MSTest v1.orderedtestsuites. I’ve since dropped back to4.23.0for the moment to work around this.I have distilled down a reproducible example, which I’ll discuss in “Issue 2”, below. The key point here is most likely that we’re targeting
.NET 4.8. A secondary indicator is apt to be not automatically producing the assembly binding redirects.I have created what should be a pretty straightforward (and hopefully consistent) repro case and pushed it to a repository - kcamp/GH-14600-selenium-4-26-1-repro
Details of my machine -
I have a few data points to share and expand on and will try to break them up as best I can 👍
Issue 1 - failure due to System.Text.Json - MSTest Deployment
First, the outright failure stemming from my [very specific!] MSTest scenario. This is a secondary presentation and in my opinion, is 100% unrelated to the issue in question, nor is it any sort of root cause. It’s simply a presentation of an error that is an unfortunate red-herring. I do want to share it for completeness and in case it helps others start an investigation of their own.
The stack trace:
I could clearly see that the [presumably correct]
System.Text.Json.dllassembly was in the\bin\Debugfolder. Enabling fusion logging showed the issue to be the attempts to probe the shadow/deployment directory. MSTest is [https://stackoverflow.com/questions/19649632/all-assemblies-are-not-getting-copied-in-test-result-ms-test](not copying) theSystem.Text.Json.dllto that folder, which is leading to the failure. We can see the dump from fusion, below.📣 For anyone finding this and attempting to debug through it, the best thing to do is probably going to be to enable fusion logging to better understand what exactly is being probed/discovered and what the underlying mismatch might be.
Issue 2 - Visual Studio Test Explorer failure due to System.Runtime.CompilerServices.Unsafe
In an effort to create a repro case, “out of the box” in a new project, I failed. Visual Studio appears to do what’s right and it all works. I tried both
net8.0andnet48. However, some more digging and thinking and I was able to get it. This goes back to the explicit suppression of the assembly binding redirect generation, mentioned above. Absent the redirects, this is the exception I get when runningMSTest.TestFrameworktests in VS2022 Test Explorer and presents with the following failure:This error is suppressed (at least for me) when creating a fresh
.csprojand the project automatically generates assembly binding redirects. I had to specify<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>in my repro project to emulate the example I am seeing in our product regression tests.It is interesting, though, that if we are observing this in the fusion log, we can also see that there’s a assembly load error reported for
System.Text.Json, it’s just not bubbling to the top of the test failure.While the error surfacing in the runner is related to
System.Runtime.CompilerServices.Unsafe, we can see fusion logs for both that assembly andSystem.Text.Jsonboth.System.Runtime.CompilerServices.Unsafe
System.Text.Json
To make the test work, we can add in the assembly binding redirect for just
System.Runtime.CompilerServices.Unsafe(below). It is important to note that we will still see the fusion log for the failed resolution ofSystem.Text.Json, but this seems to be a non-critical issue, at least in the simplified case. I suspect that adding the redirect forSystem.Text.Jsonwould be the correct thing to do, despite our stripped down example not seeming to have issues.Issue 3 - VSTest.Console failure due to System.Text.Json
An interesting behavior emerged when I was authoring some Cake scripts to help your team reproduce these - I was able to accurately reproduce the behavior seen in NUnit (below, Issue 4) from the console in VSTest. It turns out that in Issue 2, as I had alluded to, we need to place the redirect for
System.Text.Jsonas well to make the tests run from the command line.Adding both redirects resolves this error:
Issue 4 - NUnit failure due to System.Text.Json
Given what I learned in the second issue, I was able to reproduce (I am pretty sure) the exact case that @Guitrum reported.
This one, unlike the previous issue, required an assembly binding redirect for both assemblies in order to work, but once in place, the test does work without issue.
Hope this helps, if there is anything I can help to clarify, please tag me.