调用在以下方法之间是不明确的:Identical.NameSpace.InitializeComponent()和Identical.NameSpace.InitializeComponent() [英] The call is ambiguous between the following methods: Identical.NameSpace.InitializeComponent() and Identical.NameSpace.InitializeComponent()

查看:136
本文介绍了调用在以下方法之间是不明确的:Identical.NameSpace.InitializeComponent()和Identical.NameSpace.InitializeComponent()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我怀疑这可能是Visual Studio的问题,但是一定有某些原因.我从默认项列表中创建了一个ListBox(右键单击项目,或在项目中的文件夹-> Add-> New Item-> Xaml ListBox).立刻我得到一条红色的波浪线,并显示以下错误:

Ok, I suspect this might be a Visual Studio thing, but there must be some reason for this. I created from the list of default items a ListBox (Right Click on project, or folder in project -> Add -> New Item -> Xaml ListBox). Immediately I get a red squiggly line with the error:

错误2,以下方法之间的调用不明确,或者 属性:'Identical.NameSpace.ListBox1.InitializeComponent()'和 'Identical.NameSpace.ListBox1.InitializeComponent()'C:\ Documents和 设置\ ouflak \我的文档\ Visual Studio 2010 \ Projects \ Identical \ NameSpace \ ListBox1.xaml.cs 27"

"Error 2 The call is ambiguous between the following methods or properties: 'Identical.NameSpace.ListBox1.InitializeComponent()' and 'Identical.NameSpace.ListBox1.InitializeComponent()' C:\Documents and Settings\ouflak\My Documents\Visual Studio 2010\Projects\Identical\NameSpace\ListBox1.xaml.cs 27"

所有有问题的代码都是自动生成的,并且出现错误的原因是由于两个自动生成的文件之间存在冲突:ListBox1.g.cs和ListBox1.designer.cs其中public void InitializeComponent()为都在声明.在这种情况下,代码自然不能编译.只需删除ListBox1.designer.cs并继续我想的操作就足够简单了. 但是我的问题是:为什么此错误会自动生成此代码?我希望任何自动生成的内容都能够构建和编译,而无需接触项目或任何代码.对于您可以添加的几乎所有其他toobox项目,都是这种情况.那么,为什么要生成带有内置错误的代码呢?我们是否应该找到某种方法使这项工作可行?这段代码只是一个建议,由IDE用户/开发人员来敲定细节吗?

All of the code in question is auto-generated and the reason for the error is because of a conflict between two auto-generated files: ListBox1.g.cs and ListBox1.designer.cs where public void InitializeComponent() is declared in both. Naturally the code cannot compile under this circumstance. It is simple enough to just delete the ListBox1.designer.cs and move on I suppose. But my question: Why is this code auto-generated with this error? I would expect anything auto-generated to be able to build and compile without having to touch the project or any code. For just about every other toobox item that you can add, this is the case. So why generate this code with the built-in error? Are we supposed to find some way to make this work? Is this code merely a suggestion and it is up to the IDE user/developer to hammer out the details?

这是生成的代码: ListBox1.xaml:

Here is the generated code: ListBox1.xaml:

< ?xml version="1.0" encoding="utf-8" ? > 
< ListBox
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:xc="http://ns.neurospeech.com/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    x:Class="Identical.NameSpace.ListBox1"
    >
    <sys:String>Item 1</sys:String>
    <sys:String>Item 2</sys:String>
    <sys:String>Item 3</sys:String>
< /ListBox>

ListBox1.g.cs:

ListBox1.g.cs:

namespace Identical.Namespace
{
    /// <summary>
    /// ListBox1
    /// </summary>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
    public partial class ListBox1 : System.Windows.Controls.ListBox, System.Windows.Markup.IComponentConnector {

        private bool _contentLoaded;

        /// <summary>
        /// InitializeComponent
        /// </summary>
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public void InitializeComponent() {
            if (_contentLoaded) {
            return;
            }
            _contentLoaded = true;
            System.Uri resourceLocater = new System.Uri("/MyProject;component/namespace/listbox1.xaml", System.UriKind.Relative);

            #line 1 "..\..\..\namespace\ListBox1.xaml"
            System.Windows.Application.LoadComponent(this, resourceLocater);

            #line default
            #line hidden
        }

        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)     {
        this._contentLoaded = true;
        }
    }
}

ListBox1.designer.cs:

ListBox1.designer.cs:

namespace Identical.NameSpace
{
    using System;

    public partial class ListBox1 : System.Windows.Controls.ListBox
    {
        private void InitializeComponent()
        {
            // Pre Statements...
            string string1 = "Item 1";
            string string2 = "Item 2";
            string string3 = "Item 3";
            // Statements...
            this.BeginInit();
            this.Items.Add(string1);
            this.Items.Add(string2);
            this.Items.Add(string3);
            this.EndInit();
            // Post Statements...
        }
    }
}

最后是ListBox1.xaml.cs(仅进行修改以防止XML文档和Stylecop警告):

and lastly the ListBox1.xaml.cs (only modified to prevent XML documentation and Stylecop warnings):

namespace Identical.NameSpace
{
    /// <summary>
    /// ListBox1 class
    /// </summary>
    public partial class ListBox1 : ListBox
    {
        /// <summary>
        /// Initializes a new instance of the ListBox1 class
        /// </summary>
        public ListBox1()
        {
            this.InitializeComponent();
        }
    }
}

就是这样.这是完全处于原始自动生成状态的代码,除了我放入xaml.cs文件中的注释之外.

That's it. This is the code entirely in its virgin auto-generated state with the exception of the comments I put into the xaml.cs file.

我已经对该网站和互联网进行了一些搜索,但是似乎没有人解释这种行为.我可能只会删除designer.cs代码并继续前进.但是,如果有人首先知道为什么出现这种情况,或者确实是Visual Studio 2010 Professional中的错误,我真的很想知道.

I've searched this site and the internet a bit, but no one seems to have explained this behavior. I will probably just delete the designer.cs code and move on. But if anybody knows why this is here in the first place, or if it is indeed a bug in Visual Studio 2010 professional, I'd really like to know.

推荐答案

似乎您已经在类的两个位置声明了InitializeComponent方法,每个部分类中可能声明了一个.尝试在Visual Studio中的所有文件中搜索InitializeComponent,我猜测结果将列出声明它的两个位置.删除一个,错误将消失.

It appears that you have declared the InitializeComponent method in two places in your class, probably one in each partial class. Try searching in all files for InitializeComponent in Visual Studio and I'm guessing that the results will list two places where it is declared. Delete one and the error will disappear.

更新>>>

我不确定您在这里期望什么样的答案……显然,如果您没有添加这些InitializeComponent方法定义之一,则visual Studio会出现错误.我非常怀疑,除了这是一个错误之外,是否可能有任何逻辑原因.

I'm not sure what kind of answer you're expecting here... clearly, if you didn't add one of those InitializeComponent method definitions, then visual Studio has a bug. I very much doubt that there can be any kind of logical reason for this except that it's a bug.

更新2 >>>

我在 Microsoft Connect 网站上查看了任何现有的已报告的错误,但这些错误找到任何...如果您想向他们报告,我已经在这里留下了链接.

I had a look on the Microsoft Connect website for any existing reported bugs like this but couldn't find any... I've left the link here if you do want to report it to them.

这篇关于调用在以下方法之间是不明确的:Identical.NameSpace.InitializeComponent()和Identical.NameSpace.InitializeComponent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆