I am getting the following exception when running a .Net 4.6.1 unit test that uses System.IO.Compression.ZipFile.Open
, if the unit test project references a .Net Standard 2.0 assembly:
System.MissingMethodException: Method not found: 'System.IO.Compression.ZipArchive System.IO.Compression.ZipFile.Open(System.String, System.IO.Compression.ZipArchiveMode)'.
at UnitTestProject.UnitTest1.TestMethod1()
The unit test project was created using the VS 2017 Unit Test project (not the .NET Core one) and references were added to System.IO.Compression.FileSystem
and my standard class library:
using System.IO.Compression;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTestProject
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
string zipfilename = "C:\\temp\\out.zip";
using (ZipArchive zipArchive = ZipFile.Open(zipfilename, ZipArchiveMode.Read)) { }
}
}
The .net standard class library is simply a single class with no methods:
namespace StandardClassLib
{
public static class Zipper
{ // Class is empty.
}
}
I get the same error using the Test Explorer in Visual Studio and from the command line using vstest.console.exe
.
Note that this behavior only exhibits itself in a unit test project, Console Applications work fine.
Can anyone help me understand why this isn't working and a workaround to this issue (if possible)?