0

The Library loads and I am able to view the ziparchiveentries in the debugger but I can not access the methods or properties of the ziparchiveentry object array by reflection:

Assembly CompressionLib = Assembly.LoadWithPartialName("System.IO.Compression");
Module CompressionModule = CompressionLib.GetModule("System.IO.Compression.dll");
Type ZipArchiveType = CompressionModule.GetType("System.IO.Compression.ZipArchive");
Type ZipArchiveEntryType = CompressionModule.GetType("System.IO.Compression.ZipArchiveEntry");
ConstructorInfo UnzipConstructor = ZipArchiveType.GetConstructor(new[] { typeof(System.IO.Stream) });
object UnzipInstance = UnzipConstructor.Invoke(new object[] Plugin.PluginFiles[0].fileData });
MethodInfo UnzipGetEntries = ZipArchiveType.GetMethod("get_Entries");
ICollection UnzippableFilesCollection = (ICollection)UnzipGetEntries.Invoke(UnzipInstance, null);
object[] UnzippableFiles = new ArrayList(UnzippableFilesCollection).ToArray();

At this point I can view in the debugger that for example:

UnzippableFiles[25]
{pt-br/ACResources.resources.dll}
    Archive: {System.IO.Compression.ZipArchive}
    CompressedLength: 78659
    ExternalAttributes: -2119958528
    FullName: "pt-br/ACResources.resources.dll"
    LastWriteTime: {1/8/2019 7:29:04 AM -08:00}
    Length: 232696
    Name: "ACResources.resources.dll"

However example:

ZipArchiveEntryType.GetType().GetProperty("FullName").GetValue(UnzippableFiles[25])

returns with an error:

    `'ZipArchiveEntryType.GetType().GetProperty("FullName").GetValue(UnzippableFiles[25])' threw an exception of type 'System.Reflection.TargetException'`
Message: "Object does not match target type."
jazb
  • 5,498
  • 6
  • 37
  • 44
  • 1
    What if you do `UnzippableFiles[25].GetType()` in the `Watch` or `Immediate window`, what does it output? – zaitsman Jan 08 '19 at 23:53

1 Answers1

0

I managed to get it by removing the GetType() which is unresolved in context:

ZipArchiveEntryType.GetProperty("FullName").GetValue(new ArrayList((ICollection)ZipArchiveType.GetProperty("Entries").GetValue(UnzipInstance)).ToArray()[11])