Skip to content

[🐛 Bug]: [PowerShell] .NET Framework 4.8: Could not load file or assembly 'System.Text.Json, Version=8.0.0.0 #16539

@Zian

Description

@Zian

Description

When attempting to use WebDriver.dll, PowerShell displays the following message:

Could not load file or assembly 'System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

This issue is being submitted as requested by nvborisenko in a comment on a related issue (#14600).

Steps to Reproduce the Problem

Obtain a computer with the required Windows applications:

  1. Obtain a computer with Windows PowerShell 5.1 (e.g. Windows 11).
  2. Launch Windows PowerShell.
  3. Copy the following command to the Windows PowerShell window and run the command.
    [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
  4. Confirm that you see something like ".NET Framework 4.8.9310.0". The text after "4.8." can be ignored.
  5. Close Windows PowerShell.

Get the NuGet package:

  1. Go to https://www.nuget.org/api/v2/package/Selenium.WebDriver/4.38.0.
  2. (optional) Click on "Frameworks". The web page will say that .NET Framework 4.8 and .NET Framework 4.8.1 are "Compatible target framework(s)".
  3. Download the package by clicking on "Download package".
  4. Create a new folder for the files that will be obtained in the following step. This will be called the "Working Directory".

Get the Selenium files for .NET Framework 4.8:

  1. Change the download's file extension to "zip" and open the file.
  2. Extract the contents of the ZIP file to a new folder.
  3. Open the folder that was created in the previous step.
  4. Open the "lib" folder.
  5. Open the "netstandard2.0" folder. Microsoft says the files in this folder should work with .NET Framework 4.8 (https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0).
  6. Copy all the files in the "netstandard2.0" folder to the Working Directory.
  7. Return to the folder that was created at step 2.
  8. Open the "runtimes" folder.
  9. Open the "win" folder.
  10. Open the "native" folder.
  11. Copy the contents of the "native" folder to the Working Directory.
  12. Confirm that the root of the Working Directory contains at least 1 "EXE" file and at least 1 "DLL" file.
  13. (Optional) Delete the two ZIP files.

Tell Selenium where to find Selenium Manager as documented at https://www.selenium.dev/documentation/selenium_manager/#configuration:

  1. Launch Windows PowerShell 5.1.
  2. Copy the following script and paste it in the window. Then run the script. The script will determine if the environment variable has been already configured.
	$SeleniumManagerPathEnvironmentVariablePath = Join-Path `
        -Path "Env:" `
        -ChildPath "SE_MANAGER_PATH"
	$ParametersToTestSeleniumManager = @{
		Path        =
		$SeleniumManagerPathEnvironmentVariablePath
		ErrorAction ="SilentlyContinue"
	}
	$SeleniumManager = Get-Item `
		@ParametersToTestSeleniumManager
	if ($null -eq $private:seleniumManager) {
		Write-Output "The Selenium Manager Path environment variable has not been set."
	}
	else {
		Write-Warning "The Selenium Manager Path environment variable is set to `"$($SeleniumManager)`"."
		Write-Warning "This might not be the correct path."
	}
  1. If PowerShell reports that the environment variable has not been set, copy the following script and paste it in the window. Then run the script. The script will set the variable:
	# Will not persist after the PowerShell window closes
	# per
	# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.4#saving-changes-to-environment-variables
	# .
	# However, it will persist in the PowerShell window
	# even after the script terminates.
	$SeleniumManagerPath = Read-Host -Prompt "What is the path of the Selenium Manager file? Include the file extension. Do not include quotation marks around the path."
	New-Item -Path "Env:" `
		-Name "SE_MANAGER_PATH" `
		-Value $SeleniumManagerPath |
		Out-Null
  1. Copy the script from the section titled "Reproducible Code" to the PowerShell window. Run the script.

System Information

Microsoft Windows Version 22H2 (OS Build 19045.6456)

Output From $PSVersionTable in PowerShell:

Name                           Value
----                           -----
PSVersion                      5.1.19041.6456
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.6456
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Reproducible Code

$WorkingDirectoryPath = Read-Host -Prompt "Enter the full path of the Working Directory. Do not use quotation marks."
$WebDriverPath = Join-Path -Path $WorkingDirectoryPath -ChildPath "WebDriver.dll"
Import-Module $WebDriverPath

ℹ️ Last known working version: The file properties for the working version of WebDriver.dll says its file version is "4.0.0.0". Its Product version is "4".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-dotnet.NET BindingsI-defectSomething is not working as intendedI-regressionSomething was working but we "fixed" itOS-windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions