简体   繁体   English

mscorlib.dll中的'System.MissingMethodException'异常

[英]'System.MissingMethodException' exception in mscorlib.dll

I am getting an exception when debugging my program. 调试程序时出现异常。

Exception thrown: 'System.MissingMethodException' in mscorlib.dll System.Globalization.CultureInfo 引发异常:mscorlib.dll System.Globalization.CultureInfo中的“ System.MissingMethodException”

"Constructor on type 'System.Globalization.CultureInfo' not found." “找不到类型'System.Globalization.CultureInfo'的构造函数。”

at my 在我

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>

Are there any references that i need to import to make this work? 我需要导入任何参考文献才能完成这项工作吗?

The code you posted works fine, I tried it bound to a ListBox and the different cultures were displayed properly. 您发布的代码工作正常,我尝试将其绑定到ListBox并正确显示了不同的区域性。

Although I noticed the exception you described in the Output window, so I started to investigate. 尽管我注意到您在“输出”窗口中描述的异常,所以我开始进行调查。

Here you can find the source code of the ObjectDataProvider . 在这里,您可以找到ObjectDataProvider的源代码。 I linked to the part which actually interests us. 我链接到我们真正感兴趣的部分。

Here you can see that the code will actually try to create an instance of the ObjectType you provided even if you are only trying to call a static method on that type. 在这里,您可以看到代码实际上将尝试创建您提供的ObjectType的实例,即使您仅尝试对该类型调用静态方法也是如此。 This will fail with the above exception, because CultureInfo doesn't have a constructor which takes zero parameters. 由于上述异常,此操作将失败,因为CultureInfo没有采用零参数的构造函数。

This is even mentioned in the comment here : 这甚至在这里的评论中提到:

// 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)

Also I found this forum post where the accepted answer to the same question is the following: 我也发现了这个论坛帖子 ,其中相同问题的可接受答案如下:

If your application works well, you can ignore the output. 如果您的应用程序运行良好,则可以忽略输出。 This output is used for debugging the data binding errors. 此输出用于调试数据绑定错误。 But, generally even your code works well, the output may also appears, so you can ignore it. 但是,通常,即使您的代码运行良好,输出也可能会出现,因此您可以忽略它。

So I'd say you can ignore this error if your application works and as I tested it, it should work. 因此,我想说的是,如果您的应用程序可以正常工作,并且我进行了测试,则可以忽略此错误。

All that said, if you are really annoyed by the exception, you can fix it by doing the following: 综上所述,如果您真的对异常感到恼火,可以通过以下操作来解决:

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>

This won't throw the exception, because creating an instance of CultureInfo in the ObjectDataProvider 's code will succeed. 这不会引发异常,因为在ObjectDataProvider的代码中创建CultureInfo的实例将成功。 It will use the constructor which takes one string parameter. 它将使用带有一个string参数的构造函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UserManager.Create:mscorlib.dll中发生类型&#39;System.MissingMethodException&#39;的异常,但未在用户代码中处理 - UserManager.Create: An exception of type 'System.MissingMethodException' occurred in mscorlib.dll but was not handled in user code 抛出异常:System.Private.CoreLib.dll 中的“System.MissingMethodException” - Exception thrown: 'System.MissingMethodException' in System.Private.CoreLib.dll mscorlib.dll中发生了类型为&#39;System.InvalidOperationException&#39;的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll mscorlib.dll中发生了&#39;System.FormatException&#39;类型的未处理异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生了未处理的“System.StackOverflowException”类型异常 - An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll 抛出异常:mscorlib.dll 中的“System.IO.FileNotFoundException” - Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll 抛出C#异常:mscorlib.dll中的&#39;System.FormatException&#39; - C# Exception thrown: 'System.FormatException' in mscorlib.dll mscorlib.dll中发生了未处理的“System.FormatException”类型异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生类型为&#39;System.ArgumentOutOfRangeException&#39;的未处理异常 - An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll mscorlib.dll中发生了未处理的“System.UnauthorizedAccessException”类型异常 - An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM