0

Here's a situation I've found myself in quite a bit lately. Do this:

  1. In VS 2019 16.4.5, create a new C# console application targetting .net 4.7.1
  2. Add a reference to System.IO.Compression
  3. Add this line to Main() (it will crash if you actually try to run, so don't):

    var a = new System.IO.Compression.ZipArchive(System.IO.Stream.Null);

  4. Compile

  5. Examine the output exe's metadata. It will contain a reference to System.IO.Compression version 4.0, which is presumably the version included with .net 4.7.1.

Now, do this:

  1. In VS 2019 16.4.5, create a new C# console application targetting .net 4.7.1
  2. Install the nuget package System.Threading.Tasks.Extensions version 4.5.3 (latest version at the time of posting; nothing special about this package, just using it as an example)
  3. Add this line to Main() (it will crash if you actually try to run, so don't):

    var a = new System.IO.Compression.ZipArchive(System.IO.Stream.Null);

  4. Compile

  5. Navigate to the output directory. msbuild will have placed System.IO.Compression.dll there, but it's version 4.2. This appears to be because System.Threading.Tasks.Extensions has a transitive dependency on System.IO.Compression 4.2. The metadata for the compiled exe will show that it also references version 4.2 now instead of 4.0.

That's all well and good until you try to deploy the application to another machine and it fails at runtime because only version 4.0 of System.IO.Compression is included with the 4.7.1 redistributable. So what is the solution to this? Do I:

  • Deploy System.IO.Compression 4.2 with my application and have the installer copy it to the install directory alongside the exe?
  • Mess around with binding redirects?
  • Figure out what redistributable does include version 4.2, and include both that one and the 4.7.1 framework redistributable in my installer?
  • Something else entirely?
dlf
  • 9,045
  • 4
  • 32
  • 58
  • "Navigate to the output directory. msbuild will have placed System.IO.Compression.dll there", so clearly MSBuild/NuGet indicates a need to deploy that 4.2 assembly. – Lex Li Feb 25 '20 at 17:33
  • @LexLi clearly, but what is the correct (technically and legally) way of doing so? – dlf Feb 25 '20 at 17:38
  • To be clear: having the installer copy System.IO.Compression.dll version 4.2 to the install directory definitely prevents the FileNotFoundException I'd get at runtime otherwise. But I have low confidence that this is actually the right way to solve the problem. – dlf Feb 25 '20 at 17:44

0 Answers0