dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.29k stars 4.74k forks source link

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

Closed xaviergxf closed 4 years ago

xaviergxf commented 6 years ago

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.

danmoseley commented 6 years ago

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

joperezr commented 6 years ago

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>
joperezr commented 6 years ago

Let us know if that binding redirect fixes your issue.

xaviergxf commented 6 years ago

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

ianhays commented 6 years ago

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

xaviergxf commented 6 years ago

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

ianhays commented 6 years ago

@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?

xaviergxf commented 6 years ago

@ianhays here's the demo. ConsoleApp5.zip

ianhays commented 6 years ago

@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.

jnm2 commented 6 years ago

I ran into this recently too.

carlblanchard commented 6 years ago

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

joshfree commented 6 years ago

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

joperezr commented 6 years ago

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.

weshaggard commented 6 years ago

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

commonsensesoftware commented 6 years ago

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.

joperezr commented 6 years ago

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>
dejanstojanovic commented 6 years ago

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?

joperezr commented 6 years ago

@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)?

dejanstojanovic commented 6 years ago

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

dejanstojanovic commented 6 years ago

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.

dejanstojanovic commented 6 years ago

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

fabbrik commented 6 years ago

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));
                            }
                        }
                    }
tanguero commented 5 years ago

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

theodoreKor commented 5 years ago

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

carlossanlop commented 4 years ago

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.

Ganeshcse commented 4 years ago

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)