结构图和泛型(在 XML 配置中)

发布于 2024-08-07 17:41:28 字数 1945 浏览 5 评论 0原文

我正在使用最新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

银河中√捞星星 2024-08-14 17:41:28

这是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文