Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建指向从程序集动态加载的类的路由时出现问题?_C#_Asp.net Core Mvc - Fatal编程技术网

C# 创建指向从程序集动态加载的类的路由时出现问题?

C# 创建指向从程序集动态加载的类的路由时出现问题?,c#,asp.net-core-mvc,C#,Asp.net Core Mvc,我在aspnet core 3.1中工作,我有这个问题;我正在创建一个应用程序,它使用加载在配置中的dll,如以下代码块所示: //src is a Dictionary based in Assemblies dynamically loaded from dll-files. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { foreach (var src in srcs) { r

我在aspnet core 3.1中工作,我有这个问题;我正在创建一个应用程序,它使用加载在配置中的dll,如以下代码块所示:

//src is a Dictionary based in Assemblies dynamically loaded from dll-files.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{

 foreach (var src in srcs)
 {
  routes.MapRoute( 
   name : src.ControllerAlias , 
   template : src.URL , 
   defaults : new 
      { controller = src.ControllerName , action = src.Action } ,
   constraints: null,
   dataTokens : new 
   RouteValueDictionary()
    {  { "Namespaces", new string[] { src.NameSpace} } } 
    );
 } 

}
类控制器位于不同DLL中的同一命名空间中。但这不是问题,因为我能够实例所有类控制器(所有继承自控制器)

当我加载DLL时,我检查第三个mvc控制器,并且应用程序能够实例化这些类

问题是URL/端点/路由总是返回404。(无页码)

class-DLLModel
{
程序集assmbly=null,
字符串URL=“/WebServices/Home/Index.html”;
string Controller=“HomeController”;//这是一个典型的控制器示例。
string Action=“Index”;
字符串ControllerAlias=“HomeController.Index”;
string NameSpace=“Sample.Package”;
}
//...
var srcs=新字典();

SRC从何而来?显示的
src
属性包含哪些值?这是一个通用示例,实际类更复杂,但主要思想是保存控制器的字典;HomeController是VisualStudio创建的经典示例。
class DLLModel 
{
  Assembly assmbly = null ,
  string URL = "/WebServices/Home/Index.html";
  string Controller = "HomeController"; // This is a classic Controller Example.
  string Action = "Index";
  string ControllerAlias = "HomeController.Index";
  string NameSpace = "Sample.Package";
}

//...
  var srcs = new Dictionary<string,DLLModel>();