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 type 'DocumentFormat.OpenXml.Packaging.IdPartPair'] #2220

Closed
nsnhan127 opened this issue Nov 22, 2023 · 30 comments
Closed

[Could not load type 'DocumentFormat.OpenXml.Packaging.IdPartPair'] #2220

nsnhan127 opened this issue Nov 22, 2023 · 30 comments
Milestone

Comments

@nsnhan127
Copy link

In my project, I use 2 packages: ClosedXML ver 0.102.1 and DocumentFormat.OpenXml ver 3.0.0. I encountered an error when using ClosedXML to create an excel file (image below)
image

and error is : "Could not load type 'DocumentFormat.OpenXml.Packaging.IdPartPair' from assembly 'ClosedXML, Version=0.102.1.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b' due to value type mismatch."

How can i fix this issue ?

@TonyHenrique
Copy link

TonyHenrique commented Nov 22, 2023

I also have just started to get this error when I call XLWorkbook SaveAs:

System.TypeLoadException: 'Could not load type 'DocumentFormat.OpenXml.Packaging.IdPartPair' from assembly 'ClosedXML, Version=0.102.1.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b' due to value type mismatch.'

@marcosgerene
Copy link

marcosgerene commented Nov 22, 2023

Same here.

I tried to update to preview version and the problem still happens.


I downgraded from dotNet8 to dotNet6 and it works fine.

@TonyHenrique
Copy link

TonyHenrique commented Nov 22, 2023

I think that I also had DocumentFormat.OpenXml version 3.0.0
I removed it and now ClosedXML it is working again here on .NET 8

@nsnhan127
Copy link
Author

In my case, I found a solution, I lowered the version of Document.OpenXML to version 2.16.0, I no longer got the error. Hope everyone will have success with this solution

@donalddps
Copy link

@nsnhan127 can we keep this issue open or make another issue specficially for OpenXML 3.0 support? I had to downgrade OpenXML referenced in one project because it was incompatible with ClosedXML (tried the latest preview build of ClosedXML and same issue) referenced in another project.

My issue specifically was this call:
var workbook = new XLWorkbook(templatePath);

Which throws the MissingMethodException:

Method not found: 'DocumentFormat.OpenXml.OpenXmlElementList DocumentFormat.OpenXml.OpenXmlElement.get_ChildElements()'.

Downgrading OpenXML, while it may fix the issue, isn't a long-term solution.

@nsnhan127
Copy link
Author

@donalddps ok, I reopened this issue for everyone who have a better solution for any case.

@nsnhan127 nsnhan127 reopened this Dec 4, 2023
@odobrovolny-IDG
Copy link

odobrovolny-IDG commented Dec 15, 2023

I also have just started to get this error when I call XLWorkbook SaveAs:

System.TypeLoadException: 'Could not load type 'DocumentFormat.OpenXml.Packaging.IdPartPair' from assembly 'ClosedXML, Version=0.102.1.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b' due to value type mismatch.'

Hello everyone. I have exactly the same problem. We just upgraded to .net8 and ClosedXML version to 0.102.1 and this started happening. Thanks to you guys in this thread I managed to find, that downgrading OpenXML to 2.20.0 "fixes" the issue
It makes me wonder though, did they change something in ClosedXML that i can change in my code to avoid downgrading? Maybe call different method or different overload?

@Deny01
Copy link

Deny01 commented Dec 18, 2023

what's the base reason about this issue?

@davidkdb
Copy link

We have the same issue. Downgrading openXML solved it. We're also running on .NET 8.

@mariojsnunes
Copy link

Also facing the same issue. But downgrading OpenXML isn't an option as it's a peer dependency.

I'd guess updating the dependency to 3.0.0 would solve it:
https://github.com/ClosedXML/ClosedXML/blob/25eb3030e6c796df093f7e6ccdcb268dcd74b861/ClosedXML/ClosedXML.csproj#L36C5-L36C75
Any idea how difficult it is? I see a lot of breaking changes here...
https://github.com/dotnet/Open-XML-SDK/releases/tag/v3.0.0

@BieleckiLtd
Copy link

BieleckiLtd commented Jan 5, 2024

Would annotating compatible dependency version of OpenXml in ClosedXML help?

<PackageReference Include="DocumentFormat.OpenXml" Version="[2.16.0,3.0.0)" />

What this means ClosedXML accepts OpenXml 2.16.0 and up, but not 3.0.0 and higher. This should prevent it using 3.0.0 referenced by another dependency. source

jahav added a commit that referenced this issue Jan 5, 2024
…yet. Without explicit range of accepted versions, there is no warning if user has explicitely declared dependency on both v3.0 and ClosedXML 0.102*.
jahav added a commit that referenced this issue Jan 5, 2024
…yet. Without explicit range of accepted versions, there is no warning if user has explicitely declared dependency on both v3.0 and ClosedXML 0.102*.
jahav added a commit that referenced this issue Jan 5, 2024
…yet. Without explicit range of accepted versions, there is no warning if user has explicitely declared dependency on both v3.0 and ClosedXML 0.102*.
@jahav jahav added this to the v0.102.2 milestone Jan 5, 2024
@jahav jahav pinned this issue Jan 5, 2024
@jahav
Copy link
Member

jahav commented Jan 5, 2024

I have published a package 0.102.2 with explicit allowed version per @BieleckiLtd suggestion. ClosedXML isn't yet compatible with 3.0, so users will get a warning if they depend on it and it's sufficient stopgap for now. I have also pinned the issue.

image

@igitur
Copy link
Member

igitur commented Jan 5, 2024

thanks @jahav

What are the blockers for OpenXml 3.0.0 ? Is there an issue for that somewhere?

jahav added a commit that referenced this issue Jan 5, 2024
…yet. Without explicit range of accepted versions, there is no warning if user has explicitely declared dependency on both v3.0 and ClosedXML 0.102*.
@jahav
Copy link
Member

jahav commented Jan 5, 2024

@igitur I took a quick look and I am waiting for 3.1, see #2248. I don't exactly remember what consequences of wrong SpreadsheetDocumentType , but I believe it strips some parts depending on the type (e.g. VBA parts from normal workbook).. Maybe?

@igitur
Copy link
Member

igitur commented Jan 6, 2024

@igitur I took a quick look and I am waiting for 3.1, see #2248. I don't exactly remember what consequences of wrong SpreadsheetDocumentType , but I believe it strips some parts depending on the type (e.g. VBA parts from normal workbook).. Maybe?

Thanks. Yes, that definitely is a blocker!

@simonziegler
Copy link

I still get an exception. I use ClosedXML 0.102.2 and DocumentFormat.OpenXml 3.0.1.

System.TypeLoadException: Could not load type 'DocumentFormat.OpenXml.Packaging.IdPartPair' from assembly 'ClosedXML, Version=0.102.2.0, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b' due to value type mismatch.

@jahav
Copy link
Member

jahav commented Feb 7, 2024

@simonziegler And you are running incompatible major version for 0.102.2, as described in the issue (#2220 (comment)).

Update to OpenXML SDK 3.0 has been merged in #2248 for 0.104, so I am closing the issue.

@jahav jahav closed this as completed Feb 7, 2024
@simonziegler
Copy link

@simonziegler And you are running incompatible major version for 0.102.2, as described in the issue (#2220 (comment)).

Update to OpenXML SDK 3.0 has been merged in #2248 for 0.104, so I am closing the issue.

Many thanks. I'll wait for this to be available on Nuget and will try again then.

Much appreciated, Simon

@Trapulo
Copy link

Trapulo commented Feb 15, 2024

I still have the problem using 0.104.0-preview2 is this right?

@Kees-Schouten
Copy link

problem

Yes me too!

@JadynWong
Copy link

0.104.0-preview3 is still not available at nuget.

3f4e251

@mariojsnunes
Copy link

Is there an estimation for the next nuget release?
For us, this has been a dotnet8 migration blocker for a few months now.
Thanks for the hard work!

@jahav
Copy link
Member

jahav commented Mar 4, 2024

@mariojsnunes That is a self-imposed blocker, because you also updated OpenXML-SDK to a different major version. OpenXML SDK 2.* works fine on .NET8.

As for when, I am in middle (hopefully two thirds) of pivot tables refactoring and it doesn't go well. I hoped it would be done by now...

@mariojsnunes
Copy link

unfortunately for us it was another 3rd party dependency that updated OpenXML-SDK.
thanks for the update!

@test8git
Copy link

Downgrade "DocumentFormat.OpenXml" to 2.16.0 works for me

dro123 pushed a commit to dro123/ClosedXML that referenced this issue Mar 28, 2024
…l v3.0.0 yet. Without explicit range of accepted versions, there is no warning if user has explicitely declared dependency on both v3.0 and ClosedXML 0.102*.
@dluc
Copy link

dluc commented Apr 16, 2024

Is there an estimation for the next nuget release?

@GusBeare
Copy link

I just uninstalled the DocumentFormat.OpenXML package and ClosedXML works fine. I'm very confused. I thought it was a dependency? I am sure it was required when I initially installed ClosedXML. I've tried removing it and reinstalling and it doesn't require OpenXML. If it's no longer a dependency why does it show DocumentFormat.OpenXML >=2.16.0 && < 3.0.0 in the list of dependencies?

@bradleypatton
Copy link

Just ran into this issue as well after upgrading OpenXml to 3.02. Any estimate on when this will be pushed to a release? Thanks

@BieleckiLtd
Copy link

I just uninstalled the DocumentFormat.OpenXML package and ClosedXML works fine. I'm very confused. I thought it was a dependency? I am sure it was required when I initially installed ClosedXML. I've tried removing it and reinstalling and it doesn't require OpenXML. If it's no longer a dependency why does it show DocumentFormat.OpenXML >=2.16.0 && < 3.0.0 in the list of dependencies?

ClosedXML depends on DocumentFormat.OpenXML and will bring it as a transitive package. This means you do not need to include DocumentFormat.OpenXML in your project yourself. The problem arises when YOUR project also directly depends on DocumentFormat.OpenXML; in that case, you must pull the same version that ClosedXML depends on. As a reminder, the latest ClosedXML (0.102.2) depends on DocumentFormat.OpenXML (>= 2.16.0 && < 3.0.0).

@GusBeare
Copy link

Ah, many thanks for the explanation. I get it now.

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

No branches or pull requests