Using "dynamic" to use archives for the same function makes the program hang #499

Open
opened 2026-01-29 22:12:55 +00:00 by claunia · 1 comment
Owner

Originally created by @thepwrtank18 on GitHub (Feb 17, 2022).

Here is the code that decides what the dynamic is:

dynamic archive;
switch (type)
{
    case ".zip":
        archive = ZipArchive.Open(path);
        break;
    case ".7z":
        archive = SevenZipArchive.Open(path);
         break;
    case ".rar":
         archive = RarArchive.Open(path);
         break;
    default:
         throw new NullReferenceException();
}

And here is the code that extracts the files:

foreach (var entry in archive.Entries) 
{
    if (thingInZip != null && entry.Key.Contains(thingInZip))
    {
        entry.WriteToDirectory(temppath, new ExtractionOptions()
        {
            ExtractFullPath = true,
            Overwrite = true 
        });
    {
{

When doing this, unzipping the archive just makes the program hang.

Originally created by @thepwrtank18 on GitHub (Feb 17, 2022). Here is the code that decides what the dynamic is: ```cs dynamic archive; switch (type) { case ".zip": archive = ZipArchive.Open(path); break; case ".7z": archive = SevenZipArchive.Open(path); break; case ".rar": archive = RarArchive.Open(path); break; default: throw new NullReferenceException(); } ``` And here is the code that extracts the files: ```cs foreach (var entry in archive.Entries) { if (thingInZip != null && entry.Key.Contains(thingInZip)) { entry.WriteToDirectory(temppath, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); { { ``` When doing this, unzipping the archive just makes the program hang.
claunia added the bug label 2026-01-29 22:12:55 +00:00
Author
Owner

@adamhathcock commented on GitHub (Feb 21, 2022):

need more detail. but also: you don't need to do that. Just use the base interface

@adamhathcock commented on GitHub (Feb 21, 2022): need more detail. but also: you don't need to do that. Just use the base interface
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#499