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
Could not load file or assembly System.Text.Json originating from COM visible assembly #2055
Comments
Hey sorry for the late reply. Do you have a small repro which we can clone and run locally? |
Thanks for reaching out and sorry for the delay, I was out on vacation.
Attached the zip in a separate comment below.
Projects target 4.7.2 use x86 solution platform.
.sln file stored in folder ReplicateDir
projects stored in sub folders of ReplicateDir
There are two projects in the solution
ReplicatePlaywright_SJT_COM (Replicate)
DemoCallReplicatePlaywright_SJT_COM (Demo)
If Replicate is run directly, Playwright will initialize successfully and would work (see note below before running!)
If Demo is run (click test button), simply creates an instance of Replicate - you’ll eventually see the System.Text.JSON error when it spins up Playwright.
Note:
I needed to copy a .playwright folder into …ReplicateDir\DemoCallReplicatePlaywright_SJT_COM\bin
see comment in the code with the error thrown if that folder does not exist.
I have seen a feature request about being able specify the .playwright folder location somehow, which would be a nice addition.
Again thank you very much for looking at this!
|
Didn't see the zip file attach - adding |
Sorry for the late response, I was out of office. I tried to reproduce it, but was not able to. I followed the steps in the repro which included cleaning the project (remove bin and obj folder), restoring the nuget dependencies, building the project and running. I did not have to manually copy the .playwright folder over, rebuilding seems to work for me. Platform: Windows 11, VS 2022. Since I didn't modify anything, I guess net47 was used like in your use-case. |
Hum... I just tried the same thing you described, extracting the code onto a different machine. If I run ReplicatePlaywright_SJT_COM works perfectly. If I run DemoCallReplicatePlaywright_SJT_COM I get the same JSON error. |
Still trying to resolve this problem. Some more data. I uninstalled the playwright Nuget package in ReplicatePlaywright_SJT_COM. Then added System.Json.Text v 6.0.0 since that's the version the error references. Added Nuget package back got I think the root cause is that the Microsoft.Playwright Nuget package does not have a "framework" folder (e.g. 4.61) in the lib directory. and this cascades problems trying to get the relevant dll's necessary for this to work. I've tried manually getting the "matching" dll's from each package's lib folder. But there are many different mismatchs -each of the depending packages each have different folders under lib. I can see why this is difficult to get to work its a real mess. I wish there were just specific downloads of all the needed DLL's vs using Nuget. |
Hey I was developing a WPF application in .NET 5 and was having a similar error and finally just fixed it. I ended up clearing my NuGet cache, downgrading to .NET 3.1, restarting my computer, and that worked. I know it's not super specific, but I thought maybe it might help someone. |
I was trying something similar to what Julian-C10 did. After clearing everything and re-addin Playwright nuget The question I have is why is this mismatching of versions happening at all? Is there a way to simplify what Playwright needs dependency wise? Installed System.Runtime.CompilerServices.Unsafe 6.0.0 from https://api.nuget.org/v3/index.json with content hash /iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==. |
I've created a work around by putting a .config file with the below binding redirects into the directory of the application that is calling my playwright enabled assembly. But one you address that issue, you then need this: |
Closing since it seems working with the workaround above. We also bumped the JSON dependency etc. so it should not yield the same error anymore. For further issues please file a new repro. |
Hi I am facing the same error, what context info should I provide? |
Posting as a question, not a bug since my use case is unusual. Thank you in advance for any information.
I have an COM visible assembly (.dll) targeting .NET 4.7.2 that I register on target machine with with regasm /tlb /codebase
I have COMVisible=True methods that call into Playwright methods.
When those COMVisible=True methods are called from a Winforms exe (also .Net 4.7.2) that references it, Playwright functions normally. This tells me everything on the machine is installed correctly.
However, if I call my "initialize Playwright" COM Visible method from Visual Basic for Applications (32 bit).
I get System.IO.FileLoadException: Could not load file or assembly 'System.Text.Json, Version=6.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)
I set up Fusion logging and I can see that my paths for where .dll's live are correct (Expected Path is Here below)
OG: Appbase = file:///C:/.. Expected Path is Here
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.Playwright, Version=1.20.0.0, Culture=neutral, PublicKeyToken=db12f80f85d8ba23.
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Attempting download of new URL file:/// file:///C:/Expected Path is Here/System.Text.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
more of the Fusion log...
System.IO.FileLoadException: Could not load file or assembly 'System.Text.Json, Version=6.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)
File name: 'System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at Microsoft.Playwright.Transport.Connection..ctor()
at Microsoft.Playwright.Playwright.d__0.MoveNext()
The text was updated successfully, but these errors were encountered: