.Net平台下執行個體類型無法轉換成介面類型?

來源:互聯網
上載者:User

標籤:style   blog   class   code   tar   color   

首先這種情況出現在應用程式啟動前的方法裡面。

本想通過發射來實現一些功能。誰知道被這個坑了。

碰到這種問題。已經相當無語了。同時也不知道該如何解決。望有能之士幫忙解答

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 using System; using System.IO; using System.Linq; using System.Reflection; using System.Web; using System.Web.Compilation; using System.Web.Hosting; using Infrastructure;   [assembly: PreApplicationStartMethod(typeof(PreApplicationInit), "InitializePlugins")] namespace Infrastructure {     public class PreApplicationInit     {         static PreApplicationInit()         {             var pluginsPath = HostingEnvironment.MapPath("~/plugins");                           var pluginsTempPath = HostingEnvironment.MapPath("~/plugins/temp");               if (pluginsPath == null || pluginsTempPath == null)                 throw new DirectoryNotFoundException("plugins");               PluginFolder = new DirectoryInfo(pluginsPath);             TempPluginFolder = new DirectoryInfo(pluginsTempPath);         }           /// <summary>         /// The source plugin folder from which to copy from         /// </summary>         /// <remarks>         /// This folder can contain sub folders to organize plugin types         /// </remarks>         private static readonly DirectoryInfo PluginFolder;           /// <summary>         /// The folder to  copy the plugin DLLs to use for running the app         /// </summary>         private static readonly DirectoryInfo TempPluginFolder;           /// <summary>         /// Initialize method that registers all plugins         /// </summary>         public static void InitializePlugins()         {             var assemblies = PluginFolder.GetFiles("*.dll", SearchOption.AllDirectories)                     .Select(x => Assembly.LoadFrom(x.FullName));               foreach (var assembly in assemblies)             {                 var type = assembly.GetTypes().FirstOrDefault(t => t.GetInterface(typeof(IModule).Name) != null);                 if (type == null) continue;                 //Add the plugin as a reference to the application                 if (AppDomain.CurrentDomain.GetAssemblies().All(a => a.FullName != assembly.FullName))                 {                     BuildManager.AddReferencedAssembly(assembly);                 }                   //Add the modules to the PluginManager to manage them later                 var module = (IModule)Activator.CreateInstance(type);                 PluginManager.Current.Modules.Add(module, assembly);             }         }     } }

  上面是代碼。

如果通過Type.IsAssignableFrom方法來尋找介面的實現,根本查不到。

 

這是目錄結構

這是Module的實現

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 using System; using Infrastructure;   namespace NewsPlugin {     public class Module:IModule     {         public string Name {             get             {                 return "NewsPlugin";             }             set             {                 if (value == null) throw new ArgumentNullException("value");                 this.Name = value;             }         }     } }

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.