Search code examples
c#wpfform-authentication

Ambiguous Call on Microsoft WPF Authorization Example


I'm trying to learn about Form Authorization in desktop applications, and I'm following the example that Microsoft reblogged from here: http://blog.magnusmontin.net/2013/03/24/custom-authorization-in-wpf/. An error "The call is ambiguous between the following methods or properties: 'SecretWindow.SecretWindow()' and 'SecretWindow.SecretWindow()'" generates, though, at lines 316 and 318:

if (parameter == null)
    view = new SecretWindow();//Error here
else
    view = new AdminWindow();//Error here

And errors "Type ['SecretWindow' or 'AdminWindow'] already defines a member called '.ctor' with the same parameter types on these lines 431 and 457:

public SecretWindow()//Error here
{
    InitializeComponent();
}

and

public AdminWindow()//Error here
{
    InitializeComponent();
}

To me, it looks like the ambiguous calls should just be instantiating classes SecretWindow or AdminWindow, and I can't find where the methods would already be defined in the second error. Can anyone see what's going on? Thanks in advance!

EDIT:

I deleted the first project and retried the tutorial, now it works.


Solution

  • What error tells you is that both class SecretWindow and AdminWindow declare their .ctor (constructor) with exact same signature more than once. Simply said, there is more than one occurence of public SecretWindow() and public AdminWindow() throughout your project.

    As you can see, each generated view deriving from Window is a partial class, ie. it might have some of its code in other file, that also has definiton of either SecretWindow or AdminWindow.

    For Windows Presentation Foundation every window has also pregenerated file located in \obj\Debug folder called <ViewName>.g.i.cs. Try removing everything in obj\Debug folder of your project and then rebuild everything in Visual Studio.

    Fastest way to go there is right click on your project name and choose Open Folder in File explorer.