结构图和泛型(在 XML 配置中)
我正在使用最新的 StructureMap (2.5.4.264),并且我需要使用泛型在 StructureMap 的 xml 配置中定义一些实例。但是我收到以下 103 错误:
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 来验证类型实际上是否有效。有人有什么想法吗?
谢谢 !
I'm using the latest StructureMap (2.5.4.264), and I need to define some instances in the xml configuration for StructureMap using generics. However I get the following 103 error:
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)
A simply replication of the code is as follows:
public interface ITest<T>
{
}
public class Test
{
}
public class Concrete : ITest<Test>
{
}
Which I then wish to define in the XML configuration something as follows:
<DefaultInstance
PluginType="MyTest.ITest`1[[MyTest.Test,MyTest]],MyTest"
PluggedType="MyTest.Concrete,MyTest"
Scope="Singleton"
/>
I've been racking my brain, however I can't see what I'm doing wrong - I've used Type.GetType to verify the type actually is valid which it is. Anyone have any ideas?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 StructureMap 2.5.x 及更低版本中存在的错误。它已在 主干 的修订版 269 中修复,并将在 StructureMap 2.6 版本中提供。
This is a bug that exists in StructureMap 2.5.x and below. It was fixed in revision 269 in the trunk and will be available in the StructureMap 2.6 release.