mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
Unable to use Assembly.LoadFrom to call functions in a class library that depends on SharpCompress. #579
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @KaGaMiLinAlfa on GitHub (Jul 18, 2023).
I have two programs, one is a console application called ConsoleApp, and the other is a class library called ClassLibrary. Both of them are built using Core 3.1.
ConsoleApp does not reference SharpCompress, while ClassLibrary references and uses SharpCompress 33.0.
In ConsoleApp, I use Assembly.LoadFrom to load ClassLibrary and invoke related functions. However, when calling these functions
I encounter an error with the following message: 'The type initializer for 'SharpCompress.Common.ArchiveEncoding' threw an exception.'
If I add a reference to SharpCompress in ConsoleApp, the error does not occur. Why does this happen?
I want ConsoleApp to be able to call the functions in ClassLibrary without referencing SharpCompress. Is there any solution available?
I have been researching this issue for quite some time but haven't found a solution. I would appreciate any help. Thank you!
Here is the code I'm using for debugging purposes:
ConsoleApp.cs:
ClassLibrary.Class1:
@Erior commented on GitHub (Sep 4, 2023):
Have you tried Assembly.LoadFrom and dependencies ?
@KaGaMiLinAlfa commented on GitHub (Sep 15, 2023):
Thank you for your suggestion.
I have attempted to use AssemblyResolve While I successfully loaded SharpCompress.dll, it also requires the System.Text.Encoding.CodePages.dll
However, when trying to load System.Text.Encoding.CodePages.dll, I encountered the following error:
'System.Text.Encoding.CodePages, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be loaded.I can ensure that the necessary DLL files are all present. Nevertheless, I still encountered the same issue:
I have created a repository to test this issue, hoping to provide more specific information to you.
https://github.com/KaGaMiLinAlfa/SharpCompressLoadProblem.git@KaGaMiLinAlfa commented on GitHub (Jan 2, 2024):
In fact, SharpCompress did not provide support for 3.1, and I have been using Core 3.1 all along
After switching to versions 6.0 or 7.0, which clearly indicate support, it started working correctly
Thank you @Erior for telling me this answer