问题描述
我希望在运行时加载程序集,而不是在启动应用程序后启动(启动)。 为此,我通过Internet和StackOverflow搜索了许多解决方案。 我在ASP.Net Core register Controller at runtime
找到了答案 cnxiaoby说:创建ActionDescriptor并在启动时注册它。
然后,您可以在任何地方使用_partManager.ApplicationParts.Add(assembly);
一切都很好,但是我只能在运行时添加Controller类,如果要在启动应用程序后在运行时添加Razor视图,则会得到"Not Found View Index"
var newView = AssemblyLoadContext.Default.LoadFromAssemblyPath(data.FullName);
var viewAssembly = new CompiledRazorAssemblyPart(newView);
_partManager.ApplicationParts.Add(viewAssembly);
var targetAssembly = new AssemblyPart(assembly);
_partManager.ApplicationParts.Add(targetAssembly);
之后,我将“自定义操作描述符”设置为此:
MyActionDescriptorChangeProvider.Instance.TokenSource.Cancel();
编辑: 该代码在HomeController.cs和SampleAction中 如果我将所有代码放入HomeController.cs并索引“ Action”,则一切正常。 如果将代码移至其他操作(在应用程序运行并开始运行其他操作之后),则代码不起作用,并且我看到该错误。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)