1
votes

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()

1
You tested with the exact same 7z (zipped) file on both machines? - mjwills
The first parameter to SevenZipExtractor should be a fully qualified path (e.g. @"C:\Test.7z"). Have you tried that? - mjwills

1 Answers

2
votes

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.