![](/img/trans.png)
[英]UserManager.Create: An exception of type 'System.MissingMethodException' occurred in mscorlib.dll but was not handled in user code
[英]'System.MissingMethodException' exception in mscorlib.dll
调试程序时出现异常。
引发异常:mscorlib.dll System.Globalization.CultureInfo中的“ System.MissingMethodException”
“找不到类型'System.Globalization.CultureInfo'的构造函数。”
在我
xmlns:global="clr-namespace:System.Globalization;assembly=mscorlib"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
>
<Window.Resources>
<ObjectDataProvider x:Key="CulturesProvider"
ObjectType="{x:Type global:CultureInfo}"
MethodName="GetCultures">
<ObjectDataProvider.MethodParameters>
<global:CultureTypes>AllCultures</global:CultureTypes>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<CollectionViewSource x:Key="MyCVS"
Source="{StaticResource CulturesProvider}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="IetfLanguageTag" />
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<dat:PropertyGroupDescription PropertyName="Parent" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
我需要导入任何参考文献才能完成这项工作吗?
您发布的代码工作正常,我尝试将其绑定到ListBox
并正确显示了不同的区域性。
尽管我注意到您在“输出”窗口中描述的异常,所以我开始进行调查。
在这里,您可以找到ObjectDataProvider
的源代码。 我链接到我们真正感兴趣的部分。
在这里,您可以看到代码实际上将尝试创建您提供的ObjectType
的实例,即使您仅尝试对该类型调用静态方法也是如此。 由于上述异常,此操作将失败,因为CultureInfo
没有采用零参数的构造函数。
这甚至在这里的评论中提到:
// if InvokeMethod failed, we prefer to surface the instantiation error, if any.
// (although this can be confusing if the user wanted to call a static method)
我也发现了这个论坛帖子 ,其中相同问题的可接受答案如下:
如果您的应用程序运行良好,则可以忽略输出。 此输出用于调试数据绑定错误。 但是,通常,即使您的代码运行良好,输出也可能会出现,因此您可以忽略它。
因此,我想说的是,如果您的应用程序可以正常工作,并且我进行了测试,则可以忽略此错误。
综上所述,如果您真的对异常感到恼火,可以通过以下操作来解决:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
>
<Window.Resources>
<ObjectDataProvider x:Key="CulturesProvider" ObjectType="{x:Type global:CultureInfo}" MethodName="GetCultures">
<ObjectDataProvider.ConstructorParameters>
<x:Static Member="sys:String.Empty" />
</ObjectDataProvider.ConstructorParameters>
<ObjectDataProvider.MethodParameters>
<global:CultureTypes>AllCultures</global:CultureTypes>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
这不会引发异常,因为在ObjectDataProvider
的代码中创建CultureInfo
的实例将成功。 它将使用带有一个string
参数的构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.