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

Could not load file or assembly System.Text.Json originating from COM visible assembly #2055

Closed
BasketGolfer opened this issue Mar 9, 2022 · 11 comments
Labels

Comments

@BasketGolfer
Copy link

BasketGolfer commented Mar 9, 2022

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()

@yury-s yury-s transferred this issue from microsoft/playwright Mar 9, 2022
@mxschmitt
Copy link
Member

Hey sorry for the late reply. Do you have a small repro which we can clone and run locally?

@BasketGolfer
Copy link
Author

BasketGolfer commented Mar 23, 2022 via email

@BasketGolfer
Copy link
Author

Didn't see the zip file attach - adding
ReplicateDir.zip
.

@mxschmitt
Copy link
Member

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.

@BasketGolfer
Copy link
Author

BasketGolfer commented Apr 7, 2022

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.

@BasketGolfer
Copy link
Author

BasketGolfer commented Apr 27, 2022

Still trying to resolve this problem.
For those following this there are two projects, one that calls an assembly (ReplicatePlaywright_SJT_COM) that does Playwright stuff. Calling the assembly from a different project DemoCallReplicatePlaywright_SJT_COM fails. Calling the class from a form within ReplicatePlaywright_SJT_COM works.

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
Warning NU1605 Detected package downgrade: System.Text.Json from 6.0.1 to 6.0.0.
When I ran, DemoCallReplicatePlaywright_SJT_COM
The error changed now its:
Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0

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.

@Julian-C10
Copy link

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.

@BasketGolfer
Copy link
Author

I was trying something similar to what Julian-C10 did. After clearing everything and re-addin Playwright nuget
I see this in the output - when I have "fixed" the System.Text.JSON 6.0 error - then I get errors referencing System.Runtime.CompilerServices.Unsafe as described above.

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==.
Installed System.Runtime.CompilerServices.Unsafe 4.5.3 from https://api.nuget.org/v3/index.json with content hash 3TIsJhD1EiiT0w2CcDMN/iSSwnNnsrnbzeVHSKkaEgV85txMprmuO+Yq2AdSbeVGcg28pdNDTPK87tJhX7VFHw==.

@BasketGolfer
Copy link
Author

BasketGolfer commented May 26, 2022

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.
This one fixes the System.Text.JSON missmatch - its shipping the 6.0.0.1 dll but the package information is somehow saying 6.0.0.0
assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"
bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.1"

But one you address that issue, you then need this:
assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"
bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0"

@mxschmitt
Copy link
Member

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.

@BrennanOwYong
Copy link

Hi I am facing the same error, what context info should I provide?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants