mardi 8 janvier 2019

Difficulty Accessing Visible Property Using System.IO.Compression.ZipArchive by reflection (C#)

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:

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





Aucun commentaire:

Enregistrer un commentaire