未验证 提交 169ec8ef 编写于 作者: V Vladimir Sadov 提交者: GitHub

Fix leaks after unsuccessful assembly load (another try) (#68502)

* simpler fix

* Account for MONO and WASM differences when probing files

* comment

* Use TARGET_BROWSER instead

* '\\' should be normalized already by the  `GetFullPath`
上级 b44c0089
......@@ -2153,6 +2153,9 @@
<data name="FileNotFound_ResolveAssembly" xml:space="preserve">
<value>Could not resolve assembly '{0}'.</value>
</data>
<data name="FileNotFound_LoadFile" xml:space="preserve">
<value>Could not load file or assembly '{0}'. The system cannot find the file specified.</value>
</data>
<data name="Format_AttributeUsage" xml:space="preserve">
<value>Duplicate AttributeUsageAttribute found on attribute type {0}.</value>
</data>
......
......@@ -263,6 +263,12 @@ public static Assembly LoadFile(string path)
if (s_loadfile.TryGetValue(normalizedPath, out result))
return result;
// we cannot check for file presence on BROWSER. The files could be embedded and not physically present.
#if !TARGET_BROWSER
if (!File.Exists(normalizedPath))
throw new FileNotFoundException(SR.Format(SR.FileNotFound_LoadFile, normalizedPath), normalizedPath);
#endif // !TARGET_BROWSER
AssemblyLoadContext alc = new IndividualAssemblyLoadContext($"Assembly.LoadFile({normalizedPath})");
result = alc.LoadFromAssemblyPath(normalizedPath);
s_loadfile.Add(normalizedPath, result);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册