[英]How secure is it to dynamically load assemblies in ASP.NET Core 2?
[英]Dynamically loading ASP .Net Core assemblies into regular .Net Core assemblies
我有一個針對 ASP.Net Core 3.1 的項目,例如:
<Project Sdk="Microsoft.NET.Sdk.Web">
我有另一個需要動態加載上述程序集的項目(針對.Net Core 3.1,並且沒有對 ASP.Net Core 的框架引用):
var assembly = Assembly.LoadFrom(filePath);
var references = assembly.GetExportedTypes();
這在第二行失敗,但有以下例外:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'
我不記得在加載的程序集引用普通程序集時遇到過這個問題,但由於某種原因,它在 ASP 中失敗了。 如果執行加載的項目具有對 ASP.Net Core 的框架引用,則此操作成功。
如何將 ASP.Net Core 程序集加載到常規的.Net Core 程序集中?
https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#preservecompilationreferences
請記住還要加載您的項目引用的程序集,以便它能夠使用它們。 您可以通過在同一文件夾中編寫自己的所有 dll 的自動程序集加載器來完成此操作,而不是單個的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.