Reputation: 1280
The same code in .net winforms application is working on my machine while crashing on other machine with the following exception.
SevenZipExtractor.SetLibraryPath(Path.Combine(Environment.CurrentDirectory,
"x86", "7z.dll"));
var extractor = new SevenZipExtractor("myfile.7z", "abcd");
Myfile.7z have some text files with Unicode text
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
System.ArgumentException: Cannot marshal: Encountered unmappable character. at System.String.ConvertToAnsi(Byte* pbNativeBuffer, Int32 cbNativeBuffer, Boolean fBestFit, Boolean fThrowOnUnmappableChar) at System.StubHelpers.CSTRMarshaler.ConvertToNative(Int32 flags, String strManaged, IntPtr pNativeBuffer) at SevenZip.NativeMethods.LoadLibrary(String fileName) at SevenZip.SevenZipLibraryManager.LoadLibrary(Object user, Enum format) at SevenZip.SevenZipExtractor.Init(String archiveFullName) at SevenZip.SevenZipExtractor..ctor(String archiveFullName, String password) at AlMadinaLibrary.Packages.Packager.GetFileObject[T](String dibx, String fileName) at TestFile.Form1.LoadDropdownList()
Upvotes: 1
Views: 950
Reputation: 1280
The issue was the file path was having Unicode characters.
In my local machine my path was c:\data\myFile.7z
while on other machine it was c:\میرا ڈیٹا\myFile.7z
.
SevenZip is a dotnet wrapper of native 7z.dll
file and it calls the native 7z.dll
for base functionality.
The exception was coming from the dotnet native System.String.ConvertToAnsi
function and as it cannot map the Unicode characters. And because the file directory name was in the Unicode characters on other machine so it was throwing exception.
Upvotes: 2