是否可以使用 Spring.Net 代理 COM 接口?
我正在尝试使用 Spring.NET 和 C# 为 COM 接口创建动态代理。我目前正在尝试使用代码,而不是配置文件。 我的代码类似于以下内容:
Type comInterfaceType = typeof(ICOMInterface);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.AddInterface(comInterfaceType);
proxyFactory.GetProxy();
它在 GetProxy() 调用时爆炸,但出现以下异常:
System.InvalidOperationException: The property with name ArraySubType can't be found
in the type System.Runtime.InteropServices.MarshalAsAttribute, but is present as
a named property on the attributeData
[System.Runtime.InteropServices.MarshalAsAttribute(
(System.Runtime.InteropServices.UnmanagedType)28, ArraySubType = 0, SizeParamIndex
= 0, SizeConst = 0, IidParameterIndex = 0, SafeArraySubType = 0)]
这根本不可能吗?我仍在使用 Spring.NET 1.1,这在较新的版本中可能吗(我们最终将很快转向该版本)?
更新:经过实验,在代理 Form 类时,我也遇到了同样的错误,但参数略有不同(即 UnmanagementType 44)。
I am trying to create a dynamic proxy using Spring.NET and C# for a COM interface. I am currently experimenting using code, not config files.
I have code similar to the following:
Type comInterfaceType = typeof(ICOMInterface);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.AddInterface(comInterfaceType);
proxyFactory.GetProxy();
It blows up at the GetProxy() call with the following exception:
System.InvalidOperationException: The property with name ArraySubType can't be found
in the type System.Runtime.InteropServices.MarshalAsAttribute, but is present as
a named property on the attributeData
[System.Runtime.InteropServices.MarshalAsAttribute(
(System.Runtime.InteropServices.UnmanagedType)28, ArraySubType = 0, SizeParamIndex
= 0, SizeConst = 0, IidParameterIndex = 0, SafeArraySubType = 0)]
Is this simply not possible? I am still using Spring.NET 1.1, is this possible in the newer versions (which we will finally be moving to soon)?
UPDATE: After experimenting, I got this same error with slightly different parameters (ie. UnmanagedType 44) when proxying the Form class as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是 Spring.NET 1.1 中为代理方法生成属性时出现的错误造成的:https://issues.springsource.org/browse/SPRNET-852?page=com.atlassian.streams.streams-jira-plugin% 3A活动流问题选项卡。我们有一个解决方案来测试迁移到最新的 Spring 版本,所以我在那里进行了测试。它起作用了。
It seems this was a result of a bug in Spring.NET 1.1 when generating attributes for proxied methods: https://issues.springsource.org/browse/SPRNET-852?page=com.atlassian.streams.streams-jira-plugin%3Aactivity-stream-issue-tab. We have a solution to test migrating to the latest Spring version, and so I tested this there. It worked.