studyzy / imewlconverter

”深蓝词库转换“ 一款开源免费的输入法词库转换程序
GNU General Public License v3.0
7.91k stars 646 forks source link

`dotnet ImeWlConverterCmd.dll` throws NullReferenceException #318

Closed rocka closed 4 months ago

rocka commented 4 months ago

version: https://github.com/studyzy/imewlconverter/commit/9bb95ef7ab950224e89f3199f0167addaf409ff9 dotnet: 8.0.106 platform: linux-x64

$ dotnet ImeWlConverterCmd.dll -i:scel /tmp/网络流行新词【官方推荐】.scel -o:rime ./a.txt
转换开始...
03:14:34        词库(网络流行新词【官方推荐】.scel)处理出现异常:
        Object reference not set to an instance of an object.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Studyzy.IMEWLConverter.ConsoleRun.Run() in /home/runner/work/imewlconverter/imewlconverter/src/ImeWlConverterCore/ConsoleRun.cs:line 151
   at Studyzy.IMEWLConverter.Program.Main(String[] args) in /home/runner/work/imewlconverter/imewlconverter/src/ImeWlConverterCmd/Program.cs:line 34
fish: Job 1, 'dotnet ImeWlConverterCmd.dll -i…' terminated by signal SIGABRT (Abort)

git bisect result:

316e353e78e647f266f2fd0f7cffb5fb7143402e is the first bad commit
commit 316e353e78e647f266f2fd0f7cffb5fb7143402e
Author: nopdan <xci@live.com>
Date:   Mon Mar 25 05:03:09 2024 +0800

    chore: fix warning

 src/.editorconfig                                      |  7 +++++++
 src/IME WL Converter Win/Forms/MainForm.cs             |  2 +-
 src/ImeWlConverterCore/ConsoleRun.cs                   |  7 +++++--
 src/ImeWlConverterCore/Entities/WordLibraryStream.cs   |  2 +-
 src/ImeWlConverterCore/Generaters/Cangjie5Generater.cs |  2 +-
 src/ImeWlConverterCore/Helpers/HttpHelper.cs           | 11 ++++-------
 src/ImeWlConverterCore/IME/QQPinyinQcel.cs             |  4 ++--
 7 files changed, 21 insertions(+), 14 deletions(-)
 create mode 100644 src/.editorconfig
rocka commented 4 months ago

it works after reverting https://github.com/studyzy/imewlconverter/commit/316e353e78e647f266f2fd0f7cffb5fb7143402e#diff-20f08577eba7518bdb0b189dc884940a1f49c638a51935450ba4ad80a365774f

diff --git a/src/ImeWlConverterCore/ConsoleRun.cs b/src/ImeWlConverterCore/ConsoleRun.cs
index 89b05d1..4d360c9 100644
--- a/src/ImeWlConverterCore/ConsoleRun.cs
+++ b/src/ImeWlConverterCore/ConsoleRun.cs
@@ -394,7 +394,7 @@ private void LoadImeList()
                             cbxImportItems.Add(cbxa);
                             imports.Add(
                                 cbxa.ShortCode,
-                                Type.GetType(type.FullName) as IWordLibraryImport
+                                assembly.CreateInstance(type.FullName) as IWordLibraryImport
                             );
                         }
                         if (type.GetInterface("IWordLibraryExport") != null)
@@ -403,7 +403,7 @@ private void LoadImeList()
                             cbxExportItems.Add(cbxa);
                             exports.Add(
                                 cbxa.ShortCode,
-                                Type.GetType(type.FullName) as IWordLibraryExport
+                                assembly.CreateInstance(type.FullName) as IWordLibraryExport
                             );
                         }
                     }