wstring problem during swig c++ to C#
My working environment is
- Ubuntu 18.04
- ARM cpu
- Swig to C#
I did hardly built CNTK with my environment using Swig. However, When I call 'Function.Load("**.model")', there was bellow error message.
[CALL STACK]
[0x7f80a702a4] + 0x7012a4
[0x7f80bed898] CNTK:: GetFstream (std::__cxx11::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> const&, bool) + 0x200
[0x7f80a75dc4] CNTK::Function:: Load (std::__cxx11::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> const&, CNTK::DeviceDescriptor const&, CNTK::ModelFormat) + 0x7c
[0x7f80a765dc] CNTK::Function:: Load (std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>> const&, CNTK::DeviceDescriptor const&, CNTK::ModelFormat) + 0x1ac
[0x7f81638338] CSharp_CNTK_Function__Load__SWIG_0 + 0x180
[0x7f783b4a40]
at CNTK.Function._Load (System.String filepath, CNTK.DeviceDescriptor computeDevice, CNTK.ModelFormat format) [0x00031] in <b00f46cf6d58434dafaf33b4c3dc697b>:0
at CNTK.Function.Load (System.String filepath, CNTK.DeviceDescriptor computeDevice, CNTK.ModelFormat format) [0x00000] in <b00f46cf6d58434dafaf33b4c3dc697b>:0
at cntk_test.MainClass.Main (System.String[] args) [0x00012] in /home/aiware/Projects/cntk_test/cntk_test/Program.cs:17
c++ load function want wstring but c# doesn't have wstring. That is causing problem I think.
Since I did encoding them and success to load model.
var model_name = Encoding.UTF32.GetString(Encoding.UTF32.GetBytes(mname));
But when I call FindByName, it always returned null.
@CNTK developers I would get help for this problem. Maybe should I need to build with some special build options?
The problem is still there. I traced it down to wrong marshaling to wstring (.net core LPWSTR marshaler thinks wchar_t is 2-byte size, but on linux gcc it actually 4 byte in size). Here is relevant ticket in SWIG: https://github.com/swig/swig/issues/1233
Your re-encoding did not work for me; but this did work:
modelPath = Encoding.GetEncoding("UTF-16").GetString(Encoding.UTF32.GetBytes(modelPath));
Also, strings returning from CNTK are also messed up - you get only one first symbol out of full string. If you want to get input variable named 'features', you should search for variable 'f' instead. If there are ambigous variables after such truncation - well, thats bad.
Please try fix in https://github.com/swig/swig/issues/1233.