fix(webview2): fall back to byte[] assembly load and guard instance lock
Assembly.LoadFrom can fail on volumes .NET misclassifies as remote; fall back to Assembly.Load(byte[]). Broaden exception handling to BaseException for pythonnet, and skip WebView2 warmup/taskkill when the instance lock is held by another process.
This commit is contained in:
+13
-2
@@ -158,7 +158,18 @@ def get_environment(app):
|
|||||||
pass
|
pass
|
||||||
import clr
|
import clr
|
||||||
global _System
|
global _System
|
||||||
clr.AddReference(CORE_DLL)
|
# 🐛 部分机器(本机 D: 卷).NET Framework 把工程所在本地卷误判为
|
||||||
|
# “网络位置”,clr.AddReference(= Assembly.LoadFrom)报 0x80131515。
|
||||||
|
# 快路径保持 LoadFrom(正常机器行为不变);失败回落 Assembly.Load(byte[]),
|
||||||
|
# 字节加载不做路径信任分类(本机实测:D: 字节加载 OK,类型解析 OK)。
|
||||||
|
try:
|
||||||
|
clr.AddReference(CORE_DLL)
|
||||||
|
except BaseException as _ex: # pythonnet 的 .NET 异常未必是 Python Exception 子类
|
||||||
|
_msg = str(_ex).splitlines()[0][:120] if str(_ex) else type(_ex).__name__
|
||||||
|
print(f"[WV2] AddReference 路径加载失败({_msg})→ 回落 Assembly.Load(byte[])")
|
||||||
|
from System.Reflection import Assembly as _Assembly
|
||||||
|
with open(CORE_DLL, "rb") as _f:
|
||||||
|
_Assembly.Load(_f.read())
|
||||||
import System
|
import System
|
||||||
_System = System
|
_System = System
|
||||||
from Microsoft.Web.WebView2.Core import CoreWebView2Environment
|
from Microsoft.Web.WebView2.Core import CoreWebView2Environment
|
||||||
@@ -166,7 +177,7 @@ def get_environment(app):
|
|||||||
_env = _pump_wait(CoreWebView2Environment.CreateAsync(None, None, None), app)
|
_env = _pump_wait(CoreWebView2Environment.CreateAsync(None, None, None), app)
|
||||||
print(f"[WV2] {_ts()} Runtime ready: {_env.BrowserVersionString}")
|
print(f"[WV2] {_ts()} Runtime ready: {_env.BrowserVersionString}")
|
||||||
return _env
|
return _env
|
||||||
except Exception as ex:
|
except BaseException as ex: # pythonnet/.NET 异常未必是 Exception 子类,必须 BaseException
|
||||||
_env = None
|
_env = None
|
||||||
print(f"[WV2] init failed → fallback to QtWebEngine: {ex}")
|
print(f"[WV2] init failed → fallback to QtWebEngine: {ex}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user