[C#] ClearScript - 關於出現 Unhandled exception. System.TypeLoadException: Cannot load ClearScript V8 library. Load failure information for ClearScriptV8.win-x64.dll 的錯誤
2022-02-23
之前專案在測試各種在 .net 中的 Javascript Interpreter ,當然之前有測試過 Jint 當然這也是我目前主要在用的
但是之前有測試到一個叫握 ClearScript 的,是微軟的親兒子,感覺也很有搞頭,之後會有幾篇來做測試跟介紹
今天主要是執行起來的時候遇到的問題,筆記一下如何解決的..
首先,我的編譯執行環境是 Windows10 + .netcore 3.1
我在 nuget 加入 Microsoft.ClearScript.V8 ,之後執行起來就是錯了 XD
之後執行一段測試的 code 直接錯了,錯誤訊息
Unhandled exception. System.TypeLoadException: Cannot load ClearScript V8 library. Load failure information for ClearScriptV8.win-x64.dll: D:\Projects\TestProject\TestProject\bin\Debug\netcoreapp3.1\runtimes\win-x64\native\ClearScriptV8.win-x64.dll: Unable to load DLL 'D:\Projects\TestProject\TestProject\bin\Debug\netcoreapp3.1\runtimes\win-x64\native\ClearScriptV8.win-x64.dll' or one of its dependencies: 找不到指定的模組。 (0x8007007E) D:\Projects\TestProject\TestProject\bin\Debug\netcoreapp3.1\ClearScriptV8.win-x64.dll: Unable to load DLL 'D:\Projects\TestProject\TestProject\bin\Debug\netcoreapp3.1\ClearScriptV8.win-x64.dll' or one of its dependencies: 找不到指定的模組。 (0x8007007E) C:\Windows\system32\ClearScriptV8.win-x64.dll: Unable to load DLL 'C:\Windows\system32\ClearScriptV8.win-x64.dll' or one of its dependencies: 找不到指定的模組。 (0x8007007E) at Microsoft.ClearScript.V8.V8Proxy.LoadNativeLibrary(String baseName, String platform, String architecture, String extension) at Microsoft.ClearScript.V8.V8Proxy.LoadNativeAssembly() at Microsoft.ClearScript.V8.V8Proxy.OnEntityHolderCreated() at Microsoft.ClearScript.V8.SplitProxy.V8EntityHolder..ctor(String name, Func`1 acquireHandle) at Microsoft.ClearScript.V8.SplitProxy.V8IsolateProxyImpl..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort) at Microsoft.ClearScript.V8.V8IsolateProxy.Create(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort) at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort) at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags) at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints) at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(V8Runtime runtime, String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags, Int32 debugPort) at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags, Int32 debugPort) at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags) at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(String name, V8RuntimeConstraints constraints) at Microsoft.ClearScript.V8.V8ScriptEngine..ctor() at TestProject.Program.Test4() in D:\Projects\TestProject\TestProject\Program.cs:line 369 at TestProject.Program.Main(String[] args) in D:\Projects\TestProject\TestProject\Program.cs:line 384
解決方法
因為其實他是會呼叫一些需要使用到的 library 所以他在設計的為了要跨平台所以你必須要再引入 相關的資源,如果我測試平台跟目標平台
都是 Windows 就是使用 Microsoft.ClearScript.V8.Native.win-x64,當然如果你是 Linux 那就是使用 Microsoft.ClearScript.V8.Native.linux-x64
之後執行起來 就成功了 :)
網路上看到不少人碰到這問題有的說得很複雜只是清除一下專案之類的,想說就筆記一下。