Windows Phone 8.1:使用IList变量的C#回调无法转换为IVector
发布时间:2020-12-14 05:43:51 所属栏目:Windows 来源:网络整理
导读:我有一个C# windows phone 8.1 Visual Studio(2013)项目,它声明了一个回调接口 public interface ICallBack { /// summary /// The Child Callback must override this method and this will be fired when time comes /// /summary /// param name="files"T
我有一个C#
windows phone 8.1 Visual Studio(2013)项目,它声明了一个回调接口
public interface ICallBack { /// <summary> /// The Child Callback must override this method and this will be fired when time comes /// </summary> /// <param name="files">The resultant files </param> /// <param name="code">Error code</param> void GotFileList(FileType type,IList<FileInfo> files,ErrorCode code); } 我有一个C/C++X包装器,它实现如下: ref class CallbackImpl sealed : ICallBack { private: CallbackImpl(){} public: virtual void GotFileList(FileType type,Windows::Foundation::Collections::IVector<Object^>^ files,ErrorCode code); } 我的问题是在Release版本中,当C#调用ICallback :: GotFileList时 _callback.GotFileList(fileType,result as IList<FileInfo>,ErrorCode.EC_NO_ERROR); 它抛出异常System.InvalidCastException:指定的强制转换无效.该异常是指将IList转换为IVector. 调试很好;意思是,我可以向内部IList添加值并调用ICallback :: GotFileList,并且IList值在C IVector中没有任何问题. 我比较了发布/调试项目属性(在所有项目中:C#核心库,C/C++X包装器和C/C++X应用程序),并没有发现任何可以解释发布版本上的异常的差异. 有任何想法吗? 解决方法
我找到了简单的答案.由于ILIst属于专有数据类型FileInfo,因此无法转换为IVector.一旦我将接口函数签名更改为IList< Object>而不是IList< FileInfo> (以及分别在c包装中的IVector),一切正常.
这是新的代码段: public interface ICallBack { /// <summary> /// The Child Callback must override this method and this will be fired when time comes /// </summary> /// <param name="files">The resultant files </param> /// <param name="code">Error code</param> void GotFileList(FileType type,IList<Object> files,ErrorCode code); } 包装纸: ref class CallbackImpl sealed : ICallBack { private: CallbackImpl(){} public: virtual void GotFileList(FileType type,ErrorCode code); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 直线DDA,直线和圆的Bresenham算法
- .net – 通过Microsoft.Scripting和IronPython运
- 在32位Windows 7计算机上安装Python 3.5中的scip
- windows – 便携式浏览器在部署R Shiny App时出现
- windows – powershell:改变当前会话的文化
- Windows平台下kafka环境的搭建
- windows-server-2012 – Office365 DirSync Acti
- windows azure asp.net MVC2中的多租户
- windows – “Deny Logon Locally”效果
- Windows10 安装 Mysql
热点阅读