0

I have a console program that has two direct dependencies: ClosedXML v0.97 and ClosedXML.Report 0.2.4. The ClosedXML.Report dependency also depends on ClosedXML, but in a version 0.95.

When I try to compile the program in NET6 (basically only a reference to a class in the ClosedXml.Report),

_ = new XLTemplate(new System.IO.MemoryStream());

I get a compiler error

CS0012 The type 'IXLWorkbook' is defined in an assembly that is not referenced. You must add a reference to assembly 'ClosedXML, Version=0.95.0.0, Culture=neutral, PublicKeyToken=null'.

Why doesn't csc.exe recognize the 0.97 version to use and requests 0.95 (the indirect dependency)? The assembly version of package is same as the nuget version.

Nuget uses direct-dependency-wins mechanism and I though .net core also uses that for assemlby resolution. Is a mechanism different? How does roslyn resolve which version to use and when to throw an error?

Relevant piece of MSBuild

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\csc.exe 
/reference:C:\Users\username\.nuget\packages\closedxml\0.97.0\lib\netstandard2.0\ClosedXML.dll
/reference:C:\Users\username\.nuget\packages\closedxml.report\0.2.4\lib\netstandard2.0\ClosedXML.Report.dll 
jahav
  • 699
  • 1
  • 7
  • 24
  • But that's what happened, nuget decided by that rule that the 0.97.0 version was good enough to resolve the 0.95.0 dependency. A scheme that works, as long as the package author only uses the semantic version number to indicate changes and keeps the [AssemblyVersion] the same. Which they didn't do. So you really do have a dependency on 0.95.0 as well, you need to add it. Now another msbuild rule decides which one wins, adding a bindingRedirect as needed. – Hans Passant Oct 22 '22 at 18:40

1 Answers1

0

One possible explanation for this behavior would be if IXLWorkbook, which is apparently required by the call to new XLTemplate() no longer exists in Version 0.97 of ClosedXML.

If possible, try to rebuild ClosedXML.Report with ClosedXML 0.97. Since these apparently are early versions (Version < 1.0) breaking changes between versions seem possible. Also, can you make sure that the output bin directory actually contains Version 0.97?

PMF
  • 14,535
  • 3
  • 23
  • 49
  • The IXLWorkbook interface exists in both versions, I think there was a change in a signature one of methods - could that be the reason? If so, the error message is very cryptic. There is nothing in the bin directory, because the build fails to compile the program and nothing is copied to the bin. Will try to rebuild the ClosedXML.Report. – jahav Oct 22 '22 at 16:50
  • If there's a binary breaking change, errors can be cryptic. On the other hand, it's probably good you got the error at compile time. Such changes can also result in errors only at runtime. – PMF Oct 22 '22 at 18:10