Good day! Something prohibitively long poking around with a seemingly foolish venture ...
The task is to dynamically load the assembly SevenZipSharp.dll (a known library for working with archives ), then create an instance of SevenZipExtractor(string ArchiveFullName) and call the ExtractArcive(string directory) method ExtractArcive(string directory) , which should unpack the specified archive into the specified directory.
I do this:
//Π’Π°ΠΊ ΠΊΠ°ΠΊ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠ΅ΠΉ Ρ Π»ΠΈΠ±Ρ Π½Π΅Ρ, ΡΠΎ Π³ΡΡΠΆΡ ΡΠ±ΠΎΡΠΊΡ ΠΈΠ· ΡΠ΅ΡΡΡΡΠΎΠ² Π² ΠΌΠ°ΡΡΠΈΠ² Π±Π°ΠΉΡ, ΠΌΠΈΠ½ΡΡ Π²ΡΠ³ΡΡΠ·ΠΊΡ Π² ΡΠ°ΠΉΠ». var resourceBuffer = Properties.Resources.ResourceManager.GetObject(resnameSevenZipSharpLibrary) as byte[]; Assembly _SevenZipSharp = Assembly.Load(resourceBuffer); //Π‘Π±ΠΎΡΠΊΠ° ΡΡΠΏΠ΅ΡΠ½ΠΎ Π·Π°Π³ΡΡΠΆΠ°Π΅ΡΡΡ, ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΈΠ½ΡΠΎ ΠΏΠΎ ΡΠΈΠΏΡ SevenZip.SevenZipExtractor var extaractorClassType = _SevenZipSharp.GetType(SevenZip_ExtractorClassName); string ArchiveFullPath = "D:\\TEST.ARJ"; //ΠΡΠΎΠ±ΡΠ΅ΠΌ ΡΠΎΠ·Π΄Π°ΡΡ ΡΠΊΠ·Π΅ΠΌΠΏΠ»ΡΡ ΠΊΠ»Π°ΡΡΠ°, ΠΏΠ΅ΡΠ΅Π΄Π°Π² ΠΎΠ΄Π½ΠΎΠΌΡ ΠΈΠ· ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡΠΎΠ² Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ Π°ΡΠ³ΡΠΌΠ΅Π½ΡΠ° ΠΏΠΎΠ»Π½ΠΎΠ΅ ΠΈΠΌΡ Π°ΡΡ
ΠΈΠ²Π°: var Extractor = Activator.CreateInstance(extaractorClassType, new object[] { ArchiveFullPath }); Actually, this is where the application crashes:
System.Reflection.TargetInvocationException ("ΠΠ΄ΡΠ΅ΡΠ°Ρ Π²ΡΠ·ΠΎΠ²Π° ΡΠΎΠ·Π΄Π°Π» ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅.") ... Inner excepton: System.TypeInitializationException ("ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΎΡ ΡΠΈΠΏΠ° "SevenZip.SevenZipLibraryManager" Π²ΡΠ΄Π°Π» ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅.") Π² SevenZip.SevenZipLibraryManager.LoadLibrary(Object user, Enum format) Π² SevenZip.SevenZipExtractor.Init(String archiveFullName) Π² SevenZip.SevenZipExtractor..ctor(String archiveFullName) Inner excepton: System.ArgumentException ("ΠΡΡΡ ΠΈΠΌΠ΅Π΅Ρ Π½Π΅Π΄ΠΎΠΏΡΡΡΠΈΠΌΡΡ ΡΠΎΡΠΌΡ.")` If you set, for example, the path as ArchiveFullPath = "TEST.ARJ" , then it will ArchiveFullPath = "TEST.ARJ" error file not found (which is completely logical, because there is CurrentDirectory archive in CurrentDirectory ). Those. the path in the form of a short file name, he seems to be chewing, but if you specify a disk, he no longer wants.
Perhaps someone faced a similar problem, or maybe something is not doing. I already had an eye on my eyes, tried differently, through GetConstructor , for example.
Of course, it doesn't even get to the call to the ExtractArchive method.
Yes, I know that you can add a link to the assembly to the project before compiling, and use the classes from the SevenZip namespace unhindered, please do not offer this option. One could do so - the brain would not float and do it right away.
Thanks for attention!
using (var arj = new SevenZipExtractor(arjArchiveName)) { arj.ExtractArchive(targetDir); }using (var arj = new SevenZipExtractor(arjArchiveName)) { arj.ExtractArchive(targetDir); }- BlackWitcher