dotnet / Open-XML-SDK

Open XML SDK by Microsoft
https://www.nuget.org/packages/DocumentFormat.OpenXml/
MIT License
3.99k stars 544 forks source link

Bug - Method not found: 'Void DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Close() #1752

Open adamjhilton opened 1 month ago

adamjhilton commented 1 month ago

Describe the bug I updated my NuGet packages and now I'm getting this error:

System.MissingMethodException: 'Method not found: 'Void DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Close()'.'

Current versions:

The stack trace leaves my code here:

Looking at the decompiled assembly, there is a call to the [missing] OpenXmlPackage.Close() method:

 public static WmlDocument BuildDocument(List<Source> sources)
 {
  using OpenXmlMemoryStreamDocument openXmlMemoryStreamDocument = OpenXmlMemoryStreamDocument.CreateWordprocessingDocument();
  using (WordprocessingDocument wordprocessingDocument = openXmlMemoryStreamDocument.GetWordprocessingDocument())
  {
   BuildDocument(sources, wordprocessingDocument);
   ((OpenXmlPackage)wordprocessingDocument).Close();
  }

  return openXmlMemoryStreamDocument.GetModifiedWmlDocument();
 }

Here's the header from the decompiled assembly:

#region Assembly OpenXmlPowerTools, Version=4.5.3.0, Culture=neutral, PublicKeyToken=null
// C:\Users\ahilton\.nuget\packages\openxmlpowertools\4.5.3.2\lib\net45\OpenXmlPowerTools.dll
// Decompiled with ICSharpCode.Decompiler 8.1.1.7464
#endregion

I did notice that the version of the .DLL doesn't match the version of the NuGet package. I'm not sure if this is a problem or not. I don't think it is as the publish date matches. image

Solution Reverting to DocumentFormat.OpenXml v2.20.0 resolves the issue. Although, I don't think I'd classify this as a "solution". But it works for now.

Desktop (please complete the following information):

Numpsy commented 1 month ago

Removing OpenXmlPackage.Close() was listed as a breaking change in the release notes for v3 - ref https://github.com/dotnet/Open-XML-SDK/issues/1298 / https://github.com/dotnet/Open-XML-SDK/pull/1373

adamjhilton commented 1 month ago

Ah... So, the author of the DocumentBuilder class in the OpenXmlPowerTools assembly hasn't removed the call to OpenXmlPackage.Close() yet? Got it. Hopefully, they'll update it eventually.

moosa-bah commented 3 weeks ago

Have you resolved that? I still have that error and couldn't remove OpenXmlPackage.Close(), because the method DocumentBuilder.BuildDocument has that error.