是否可以使用 Spring.Net 代理 COM 接口?

发布于 2024-09-24 15:49:25 字数 892 浏览 10 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(1

燕归巢 2024-10-01 15:49:25

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

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