uwp - UWP System.InvalidCastException:无法转换 COM 对象
问题描述
我有一个针对 FCU 的 UWP 应用程序。从今天开始,我收到以下异常:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. 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.
at MoneyFox.Windows.Views.AccountListView.AccountListView_obj1_Bindings.Update_CurrentBalance(Double obj, Int32 phase)
at MoneyFox.Windows.
据我所见,一旦与 TextBlock 的类型为 double 的绑定更新,就会发生这种情况。但我没有更改该代码的任何内容。
我有最新的 VS 15.7.3。我还尝试针对不同平台和不同版本的 Microsoft.NETCore.UniversalWindowsPlatform(当前为 6.0.8)。
存储库的链接:https ://github.com/NPadrutt/MoneyFox.Windows/tree/XamarinFormsNew
那会是什么?
解决方案
我发现了问题。我有一个转换器,它通过 Xamarin.Forms 实现 IValueConverter 并从 MvxValueConverter 继承,因此我可以将它用于 Xamarin Forms Bindings 以及没有 XF 的 UWP 应用程序。
public class AmountFormatConverter : MvxValueConverter, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// Converter Logic
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// Convert Back Logic
}
}
我的问题是,我没有为实现的方法设置 Override 关键字。似乎导致了这个问题。
public class AmountFormatConverter : MvxValueConverter, IValueConverter
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
// Converter Logic
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// Convert Back Logic
}
}
推荐阅读
- jenkins - 用声纳设置詹金斯时出错
- sql - SQL 查询在同一查询中查找值、日期和公司之间的最小值和最大值
- python - 合并两个排序的链表 - Python 实现 - 错误/不完整的输出
- pygame - 无法在pycharm中安装pygame
- matrix - Z = -1 处图像平面的逆相机内在矩阵
- c - createIndexes 中的错误:无法使用数据库“mydb”发送“createIndexes”命令:无法读取 4 个字节:套接字错误或超时
- html - 如何让一个 div 作为一个盒子不跨越/离开屏幕
- django - 在这种情况下发布多种形式的同一模型的最佳方式是什么?
- vbscript - 循环一行不断增加的代码
- ruby - OpenURI 未能遵循具有 %20 的 URL