Runtime: System.MissingMethodException : Method not found: 'Void System.IO.Compression.ZipFileExtensions.ExtractToFile(System.IO.Compression.ZipArchiveEntry, System.String, Boolean)'

Created on 9 Feb 2018  路  26Comments  路  Source: dotnet/runtime

I'm having the following error when targetting netappcore2.0 and net471:

System.MissingMethodException : Method not found: 'Void System.IO.Compression.ZipFileExtensions.ExtractToFile(System.IO.Compression.ZipArchiveEntry, System.String, Boolean)'.

Is this a new bug? Is there any workaround available?

Thanks.

area-System.IO.Compression bug tracking-external-issue

Most helpful comment

The amount of time I spent with no luck trying to fix this issue is ridiculous. If u need a workaround look at this code snippet (at least will get u going):

using (var zip = new ZipArchive(file.InputStream))
                    {
                        foreach (ZipArchiveEntry entry in zip.Entries)
                        {
                            if (!string.IsNullOrEmpty(Path.GetExtension(entry.FullName))) //make sure it's not a folder
                            {
                                **var  deflate_stream = entry.Open();
                                using (var fileStream = System.IO.File.Create(Path.Combine(uploads, entry.FullName)))
                                {
                                    deflate_stream.CopyTo(fileStream);
                                }**

                            }
                            else
                            {
                                Directory.CreateDirectory(Path.Combine(uploads, entry.FullName));
                            }
                        }
                    }

All 26 comments

@joperezr is this one of the known issues in 471?

Yes, I believe the problem here is that you are missing a binding redirect to System.IO.Compression.ZipFile. This will be automatically generated for you when we ship VS 15.6, but for the time being, can you please try adding the following binding redirect manually to your net471's app.config?

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.IO.Compression.ZipFile" culture="neutral" publicKeyToken="b77a5c561934e089" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

Let us know if that binding redirect fixes your issue.

Hi @joperezr, thanks for the workaround. If this is a problem with vs, then i could use the cli instead? Thanks

@joperezr @xaviergxf have either of you tried it using the latest VS 15.6 preview version?

@ianhays i didn't tried. I try my best not to use something in preview that we'll damage my productivity :)

@xaviergxf totally understand, thanks for the quick response :)

I made a simple app on the latest VS preview version and couldn't repro the issue, but I wanted to make sure I'm testing the right thing. Do you have a small repro program or example that you could provide that I can test with the latest VS Preview to make sure this has been resolved?

@ianhays here's the demo.
ConsoleApp5.zip

@joperezr FYI:

This is still broken on the latest VS preview.

In fact, referencing net471 as a targetframework seems pretty broken all around. I tried just targeting net471 without netcoreapp and I get Assets file '...project.assets.json' not found. Run a NuGet package restore to generate this file. This is after a full clean and deletion of all bin/obj folders.

I ran into this recently too.

Yup, not working for me neither, the workaround did nothing.

@weshaggard is this something you could help load balance for us?

Can anyone hitting this upgrade to VS 15.6.3? We added a fix in the tooling that should fix the automatic binding redirect issue and reference the right dll which should have the method.

I suspect this is the VS issue that @joperezr is referencing.

I'm running 15.6.3 and I'm hitting a related issue. My project uses CPS with TargetFrameworks for net452 (using full .NET refs only) and net461 (using NuGet refs). Everything compiles, but I get MissingMethodException from ZipFile.OpenRead at runtime in the net461 build. The net452 build runs fine.

ZipFile is a very specific case that won't be fixed by VS 15.6.3. For this very particular issue, do you mind adding a binding redirect into your net461's app.config?

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.IO.Compression.ZipFile" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

Hi, I have the same issue. I tried adding the assemblyBinding section to app.config, but it is still failing to load the proper assembly and I am getting MissingMethodException

Unhandled Exception: System.MissingMethodException: Method not found: 'Void Syst em.IO.Compression.ZipFileExtensions.ExtractToFile(System.IO.Compression.ZipArchi veEntry, System.String, Boolean)'.

Any other suggestion how to resolve this issues?

@dejanstojanovic which version of ZipFile do you depend on? which version of the framework are you targeting (4.7.1 or 4.7.2)? which version of the framework are you running in(is installed on your machine)?

Hi,
The application is targeting 4.6.1 and I am referencing the nuget System.IO.Compression.ZipFile in the packages.config
<package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net461" />
On the target machine I checked the registry for the framework version of framework and according to https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed it has framework 4.7.1 installed
image

I just discovered one more weird thing. On the target machine I went to GAC C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.IO.Compression.ZipFile\v4.0_4.0.0.0__b77a5c561934e089 to check the version of System.IO.Compression.ZipFile.dll with simple PowerShell command

([system.reflection.assembly]::loadfile("C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.IO.Compression.ZipFile\v4.0_4.0.0.0__b77a5c561934e089\System.IO.Compression.ZipFile.dll")).FullName

The output is
System.IO.Compression.ZipFile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The same output I get for the assembly I referenced via nuget package and I am getting the same response, however the files are not the same. Easily noticeable by file size which is different.

So as far as I see, there are two assemblies which are obviously different but they have the same version?
I think this is the reason why config assembly resolution policy looks like not working.

Finally made it work.
I installed 4.7.1 SDK on my dev machine, set the targeting framework to 4.7.1 instead of 4.6.1, removed all packages and added references installed and re-compiled.

Finally works

The amount of time I spent with no luck trying to fix this issue is ridiculous. If u need a workaround look at this code snippet (at least will get u going):

using (var zip = new ZipArchive(file.InputStream))
                    {
                        foreach (ZipArchiveEntry entry in zip.Entries)
                        {
                            if (!string.IsNullOrEmpty(Path.GetExtension(entry.FullName))) //make sure it's not a folder
                            {
                                **var  deflate_stream = entry.Open();
                                using (var fileStream = System.IO.File.Create(Path.Combine(uploads, entry.FullName)))
                                {
                                    deflate_stream.CopyTo(fileStream);
                                }**

                            }
                            else
                            {
                                Directory.CreateDirectory(Path.Combine(uploads, entry.FullName));
                            }
                        }
                    }

Finally made it work.
I installed 4.7.1 SDK on my dev machine, set the targeting framework to 4.7.1 instead of 4.6.1, removed all packages and added references installed and re-compiled.

Finally works

will try this, thanks for sharing the wisdom

For a similar exception I got when trying to zip a simple file :

Unhandled Exception: System.MissingMethodException: Method not found: 'Void System.IO.Compression.DeflateStream.

I deleted the references for System.IO.Compression and System.IO.Compression.FileSystem and added them again and it worked.

Solution based on this link:
https://social.msdn.microsoft.com/Forums/en-US/f8b29f09-48d8-4364-9c79-b62e38909c18/c-systemmissingmethodexception-when-trying-to-open-and-read-from-file-in-ziparchive?forum=csharpgeneral

Judging by the last two replies by @dejanstojanovic and @theodoreKor stating that the problem has been resolved, and the fact that there are no more additional reports since July, I will close this issue.

If this is still a problem, feel free to reopen.

Hi,
This issue is happening for me when I am running my WPF application on Windows 7 machine.
My machine is pre-installed .Net 4.7 and my application on top installs .Net 4.7.1 but when I run my application this issue happens while accessing Zip.OpenRead() method.

It says "MethodNotFound"

Like below
System.MissingMethodException: 'Method not found: 'System.IO.Compression.ZipArchive System.IO.Compression.ZipFile.OpenRead(System.String)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chunseoklee picture chunseoklee  路  3Comments

aggieben picture aggieben  路  3Comments

jamesqo picture jamesqo  路  3Comments

omariom picture omariom  路  3Comments

omajid picture omajid  路  3Comments