0
我正在使用最新的StructureMap(2.5.4.264),我需要使用泛型在StructureMap的xml配置中定義一些實例。不過,我得到以下103錯誤:結構圖和泛型(在XML配置中)
Unhandled Exception: StructureMap.Exceptions.StructureMapConfigurationException: StructureMap configuration failures:
Error: 103
Source:
Requested PluginType MyTest.ITest`1[[MyTest.Test,MyTest]] configured in Xml cannot be found
Could not create a Type for 'MyTest.ITest`1[[MyTest.Test,MyTest]]'
System.ApplicationException: Could not create a Type for 'MyTest.ITest`1[[MyTest.Test,MyTest]]' ---> System.TypeLoadException: Could not loa
d type 'MyTest.ITest`1' from assembly 'StructureMap, Version=2.5.4.264, Culture=neutral, PublicKeyToken=e60ad81abae3c223'.
at System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&
stackMark, Boolean loadTypeFromPartialName)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark&
stackMark)
at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& s
tackMark)
at System.Type.GetType(String typeName, Boolean throwOnError)
at StructureMap.Graph.TypePath.FindType()
--- End of inner exception stack trace ---
at StructureMap.Graph.TypePath.FindType()
at StructureMap.Configuration.GraphBuilder.ConfigureFamily(TypePath pluginTypePath, Action`1 action)
一個簡單的代碼複製如下:
public interface ITest<T>
{
}
public class Test
{
}
public class Concrete : ITest<Test>
{
}
,然後我想在XML配置的東西來定義如下:
<DefaultInstance
PluginType="MyTest.ITest`1[[MyTest.Test,MyTest]],MyTest"
PluggedType="MyTest.Concrete,MyTest"
Scope="Singleton"
/>
我一直在拍我的大腦,但是我看不到我在做什麼錯 - 我用Type.GetType來驗證它實際上是有效的類型。有人有主意嗎?
謝謝!
看起來您的示例中的泛型沒有正確顯示。確保您使用stackoverflow的代碼格式化程序來格式化所有代碼 - 包括您的類和接口聲明。 – 2009-10-08 14:12:43
你是對的 - 修復。謝謝 – 2009-10-08 16:45:18