3

I am working on a WPF project and I just came across a weird error, I have code that runs perfectly fine but has 16 errors in the form of 2:

IComponentConnector.Connect(int, object)' is explicitly implemented more than once

(In the same document at the same space I might add) and 14 ambiguity errors due to this. All of this happened after I added a button, but removing it does nothing.

As I said before the project runs perfectly fine, but it seems to think as if there are duplicates of the code?

Completely recreating the window does nothing either and the "errorscribbles" don't even show up. I seem to be only one suffering from this as I could not find anything online cept This which is a similar but not equal problem.

Could it be the version I am running? I have .NET 5.0, but changing this does nothing. I am really out of ideas and in the worst case scenario il just live with the errors.

The code that is getting the error:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Eu4MissionDesigner
{
    /// <summary>
    /// Interaction logic for DirSelectWindow.xaml
    /// </summary>
    public partial class DirSelectWindow : Window
    {
        public DirSelectWindow(FileDirs FileDirectories)
        {
            InitializeComponent();

            FileDirs fdDW = FileDirectories;

            if (fdDW != null)
            {
                if (fdDW.LocDir == null) { LocDirBlock.Text = "No Directory"; } else { LocDirBlock.Text = fdDW.LocDir; }
                if (fdDW.ImgDir == null) { ImgDirBlock.Text = "No Directory"; } else { ImgDirBlock.Text = fdDW.ImgDir; }
                if (fdDW.MisDir == null) { MisDirBlock.Text = "No Directory"; } else { MisDirBlock.Text = fdDW.MisDir; }
            }
        }

        private void LocButtClick(object sender, RoutedEventArgs e)
        {
        }
    }
}

It is really simple code and I don't see what could be wrong. It keeps referring to:

public DirSelectWindow(FileDirs FileDirectories)

as if it is something wrong (no errors in other documents, could post entire project if necessary).

Sorry for my English, I am using the last of my mental capacity left to write this

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Grusen
  • 31
  • 4
  • How this `DirSelectWindow` gets initialized? If you are not using any application framework that automates the injection part it will cause some issues. – Eldar Aug 04 '21 at 19:22
  • `private void DirButtClick(object sender, RoutedEventArgs e) { DirSelectWindow DirWin = new DirSelectWindow(fd); DirWin.Show(); }` It has worked hundreds of times before and I don't think it is the culprit. I am so sorry for the formatting – Grusen Aug 04 '21 at 20:07

3 Answers3

4

With my issue, After Copying a View, or some of another's code, I'd have to go into the new view's .cs file and manually change the Partial Class and the public class because they also duplicated from the copied view.

drpepper1324
  • 113
  • 9
  • I think its worth noting that the "x:Class" field in the xaml needs to be changed. I was scratching my head trying to figure out where my copied file had any leftover incompatible names from the old view until I noticed this. – Connell Hagen Aug 28 '23 at 16:32
0

I restarted my computer and it fixed itself. Mind you, restarting the program itself did nothing. This must have been something to do with my windows, maybe an update?

Grusen
  • 31
  • 4
0

In my case this seems to have been caused by a project directory which contained other projects inside it. That seems to work fine in .NET Framework, but .NET Core showed the inside projects as folders of code in the top project causing duplicate code that VS is complaining about.

Solution - make each project a separate directory in the solution.

viraptor
  • 33,322
  • 10
  • 107
  • 191