1

我有一个 Excel 加载项,我目前正在尝试为其设置单元测试框架。对于单元测试,我遵循了本指南:http: //blogs.msdn.com/b/varsha/archive/2010/08/17/writing-automated-test-cases-for-vsto-application.aspx

它似乎工作正常,直到我想从我的界面返回一个类对象。将类对象指定为返回类型会在调用方法时引发“返回参数具有无效类型”异常。将返回类型从类更改为对象允许我调用方法并获取对象,但现在我无法将其转换为类并按预期使用它,当我尝试时收到此异常消息:

> Unable to cast COM object of type 'System.__ComObject' to class type
> 'XYCoordinates'. Instances of types that represent COM
> components cannot be cast to types that do not represent COM
> components; however they can be cast to interfaces as long as the
> underlying COM component supports QueryInterface calls for the IID of
> the interface.

我已经使用 VisualBasic.Information.TypeName 检索了类型名称,并将其显示为我期望的类。

有什么办法可以让 comobject 重新回到课堂上?或者另一种访问它拥有的属性的方法?还是我在这里有点愚蠢?

4

0 回答 0