The call is ambiguous between the following methods: Identical.NameSpace.InitializeComponent() and Identical.NameSpace.InitializeComponent()

和自甴很熟 提交于 2019-12-01 15:23:18

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.


UPDATE >>>

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.

UPDATE 2 >>>

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.

I had this issue when copying my XAML between controls. I just had to change my x:Class="mynamespace" where mynamespace is the proper namespace for your project. Recompiled and all went back to normal.

My problem was the project that was giving me the ambiguous call had a reference to its own dll. This was causing the method to be referenced from the dll as well as in the actual project. Once i removed the dll from the references the ambiguous call error went away.

Can happen if you are not alert and careful about how you use Resharper.

This happened to me when a I allowed Resharper to auto-import references while I was coding.

So having mistyped initially, then edited the code I was working on, I did not check what it had imported. After running into the same issue, I realised that there was a self-reference in the same library. So there were double implementations of the method in question.

Both classes are partial, meaning they share each others non private fields & methods.

Your ListBox1 does have two InitializeComponent (shared) methods. Changing the namespace of either ListBox1 will resolve this error.

Hozefa Laxmidhar

I think InitializeComponent() is declared in two different locations in the same class.

Try to find both class definitions using CTR+F and then resolve solve the ambiguity.

I ran into this issue, with a user control and an associated style. I think I had tried to move some logic into the style class but it didn't work, so I undid it, but apparently something got left behind.

It was also complaining about the _contentLoaded variable, so I tried deleting the one that was there, and the error went away, and was not replaced with another error. I then hit F12 to go to _contentLoaded's definition and found that it was in the *.g file for the style class. Though the file was named after the style, the class inside was named after the user control.

I deleted the bin and obj folders to resolve it.

I managed to resolve this by looking inside the .csproj file with a text editor and looking for the name of the Table Adapter XSD file. I found two references to it one with a different alias name hence why I was getting this error message.

I have just had and resolved this exact thing..

It happened at some point during or after I duplicated a form, in a WinForms program, then renamed it to blah_Copy.

The main cs file and the designer cs file, are both partial classes. So if a method is defined in both and it has the same name and parameters (or same name and same no paramters) , / same signature then it will clash.

In my case they both, both Initialize() { .. } definitions, had identical bodies so I easily just removed one.

Also let's say the method is Initialize() (it was in my case). If you go to call itself, then hit F12 it will go to one of((or perhaps even at least one), of the definitions.

I fixed this issue by cleaning up the bin and obj folders. You can try to remove these two folders and then rebuild the solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!