2012-01-09 186 views
0

我正在使用結構化地圖從子目錄加載插件。動態加載的類缺少屬性

主應用程序和插件都引用FileHelpers dll。 FileHelpers具有屬性,您可以將其放在類中以定義記錄由哪些分隔。這些在我的插件中定義。例如。

[Delimited('\t')] 
public class Test { 
    public string name; 
} 

FileHelpers utitlity使用插件提供的類定義從主應用程序運行。如果我將插件DLL放在主應用程序下的目錄中,那麼我會遇到FileHelpers庫的一個問題,抱怨找不到該屬性,但是如果將它放在主庫(相同的文件夾)旁邊,那麼它工作正常。

我已經把一些進一步的調試語句到我的代碼,並發現,如果

var type = typeof(Test); 
var attributes = type.GetCustomAttributes(true); 

使用,而不是特定的(一個FileHelpers使用)

var attributes = type.GetCustomAttributes(typeof(DelimitedAttribute), true); 

然後找到自定義屬性沒有任何麻煩。

我認爲這可能是一個SM的東西,但嘗試過MEF,並通過使用Assembly.Load()來做同樣的事情。

+0

'type'代表'Test'類型還是'Test'的祖先? – 2012-01-09 02:00:10

+0

對不起yes..test代表測試類型 – Schotime 2012-01-09 02:15:39

+0

也許我錯過了某些東西,但是'Type.GetCustomAttributes(bool)'根據[MSDN文檔](http://docs.sourceforge.net/)沒有看到是'GetCustomAttributes'的有效重載。 /msdn.microsoft.com/en-us/library/system.attribute.getcustomattributes.aspx)。這是什麼特定於StructureMap?其中一個是 – 2012-01-09 03:22:11

回答