I get a Value cannot be null error on some gzips but not others #348

Open
opened 2026-01-29 22:10:29 +00:00 by claunia · 9 comments
Owner

Originally created by @rickyelqasem on GitHub (Mar 19, 2019).

I get error: System.ArgumentNullException: 'Value cannot be null. Parameter name: path2' on some gzips but not others that are in the same directory when I try to extract them

string endTarget = @"d:\TestUEF";
string[] files2 = Directory.GetFiles(sourcePath);
foreach (string file in files2)
{
string filePath = @file;
using (Stream stream = File.OpenRead(filePath))
{
var reader = ReaderFactory.Open(stream);
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
reader.WriteEntryToDirectory(endTarget, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
}
}
}
}

Originally created by @rickyelqasem on GitHub (Mar 19, 2019). I get error: System.ArgumentNullException: 'Value cannot be null. Parameter name: path2' on some gzips but not others that are in the same directory when I try to extract them string endTarget = @"d:\TestUEF"; string[] files2 = Directory.GetFiles(sourcePath); foreach (string file in files2) { string filePath = @file; using (Stream stream = File.OpenRead(filePath)) { var reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(endTarget, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); } } } }
Author
Owner

@adamhathcock commented on GitHub (Mar 20, 2019):

Stacktrace and version is needed

@adamhathcock commented on GitHub (Mar 20, 2019): Stacktrace and version is needed
Author
Owner

@rickyelqasem commented on GitHub (Mar 20, 2019):

Not working zip > https://bit.ly/2TPl9lm
Working zip > https://bit.ly/2TNCR8W
.net = 4.6.1
sharpcompress = Install-Package sharpcompress -Version 0.23.0

System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Parameter name: path2
Source=mscorlib
StackTrace:
at System.IO.Path.Combine(String path1, String path2)
at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry entry, String destinationDirectory, ExtractionOptions options, Action`2 write)
at SharpCompress.Readers.IReaderExtensions.WriteEntryToDirectory(IReader reader, String destinationDirectory, ExtractionOptions options)
at UEF_Extractor.Form1.extractUEFFilesToolStripMenuItem_Click(Object sender, EventArgs e) in D:\OneDrive\devwork\UEF Extractor\UEF Extractor\Form1.cs:line 84
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.MenuStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at UEF_Extractor.Program.Main() in D:\OneDrive\devwork\UEF Extractor\UEF Extractor\Program.cs:line 19

@rickyelqasem commented on GitHub (Mar 20, 2019): Not working zip > https://bit.ly/2TPl9lm Working zip > https://bit.ly/2TNCR8W .net = 4.6.1 sharpcompress = Install-Package sharpcompress -Version 0.23.0 System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. Parameter name: path2 Source=mscorlib StackTrace: at System.IO.Path.Combine(String path1, String path2) at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry entry, String destinationDirectory, ExtractionOptions options, Action`2 write) at SharpCompress.Readers.IReaderExtensions.WriteEntryToDirectory(IReader reader, String destinationDirectory, ExtractionOptions options) at UEF_Extractor.Form1.extractUEFFilesToolStripMenuItem_Click(Object sender, EventArgs e) in D:\OneDrive\devwork\UEF Extractor\UEF Extractor\Form1.cs:line 84 at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.MenuStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at UEF_Extractor.Program.Main() in D:\OneDrive\devwork\UEF Extractor\UEF Extractor\Program.cs:line 19
Author
Owner

@rickyelqasem commented on GitHub (Mar 20, 2019):

Its got something to do with the contents which is a file without the filename attribute so when I extract with winrar it gives the file the same name as the zip with the .zip extension.

@rickyelqasem commented on GitHub (Mar 20, 2019): Its got something to do with the contents which is a file without the filename attribute so when I extract with winrar it gives the file the same name as the zip with the .zip extension.
Author
Owner

@adamhathcock commented on GitHub (Mar 20, 2019):

Since that's the case, you should can handle it yourself.

The WriteEntryToDirectory type methods are extensions to make common scenarios easy but it doesn't handle everything. My intent isn't to have a fully fledged WinZip/WinRAR UI facing library but a more raw one that allows developers to do what they need to more easily. I've tried to avoid doing a lot of file-facing things.

@adamhathcock commented on GitHub (Mar 20, 2019): Since that's the case, you should can handle it yourself. The `WriteEntryToDirectory` type methods are extensions to make common scenarios easy but it doesn't handle everything. My intent isn't to have a fully fledged WinZip/WinRAR UI facing library but a more raw one that allows developers to do what they need to more easily. I've tried to avoid doing a lot of file-facing things.
Author
Owner

@rickyelqasem commented on GitHub (Mar 20, 2019):

I actually found an alternate going back to system.io.compress > https://stackoverflow.com/questions/24138373/unzip-gz-file-using-c-sharp < this is working for me now.

@rickyelqasem commented on GitHub (Mar 20, 2019): I actually found an alternate going back to system.io.compress > https://stackoverflow.com/questions/24138373/unzip-gz-file-using-c-sharp < this is working for me now.
Author
Owner

@Bond-009 commented on GitHub (Sep 21, 2021):

no-filename.gz
A test file for whoever wants to fix this and a test

@Bond-009 commented on GitHub (Sep 21, 2021): [no-filename.gz](https://github.com/adamhathcock/sharpcompress/files/7199548/no-filename.gz) A test file for whoever wants to fix this and a test
Author
Owner

@Rombersoft commented on GitHub (Jul 8, 2024):

I see this bug is not fixed yet. Version 0.37.2

@Rombersoft commented on GitHub (Jul 8, 2024): I see this bug is not fixed yet. Version 0.37.2
Author
Owner

@adamhathcock commented on GitHub (Jul 9, 2024):

You can fix it yourself and please add a test. My comment still stands about the convenience method and the ability to handle all entries the way you want to.

@adamhathcock commented on GitHub (Jul 9, 2024): You can fix it yourself and please add a test. My comment still stands about the convenience method and the ability to handle all entries the way you want to.
Author
Owner

@henkgl commented on GitHub (Nov 12, 2024):

A workaround for this issue, which worked for me is the following:
Instead of using:

using (var archive = ArchiveFactory.Open(filePath))
{
    archive.ExtractToDirectory(folderPath);
}

Use this:

using (var stream = File.OpenRead(filePath))
{
    var reader = ReaderFactory.Open(stream);
    while (reader.MoveToNextEntry())
    {
        if (!reader.Entry.IsDirectory)
        {
            reader.WriteEntryToDirectory(folderPath, new ExtractionOptions() { ExtractFullPath = true });
        }
    }
}
@henkgl commented on GitHub (Nov 12, 2024): A workaround for this issue, which worked for me is the following: Instead of using: ```c# using (var archive = ArchiveFactory.Open(filePath)) { archive.ExtractToDirectory(folderPath); } ``` Use this: ```c# using (var stream = File.OpenRead(filePath)) { var reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(folderPath, new ExtractionOptions() { ExtractFullPath = true }); } } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#348