Visual Studio 2010 C# "already defined a member with same parameter types error."
Asked Answered
M

5

7

im having a problem in visual studio it keeps saying i have defined a member with same parameter types. Im new to C# programming and i dont really know what to do. These are the errors that are occurring:

Error 1 Type 'Secret.AddPage' already defines a member called 'AddPage' with the same parameter types

Error 2 Type 'Secret.AddPage' already defines a member called 'PhoneApplicationPage_Loaded' with the same parameter types

Here is the code i have written so far any help is greatly appreciated.

enter code here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Device.Location;

namespace secret
{
public partial class AddPage : PhoneApplicationPage
{
    private string location = "";

    public AddPage()
    {
        InitializeComponent();

        GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher();
        var myPosition = myWatcher.Position;

        // Eftersom koden körs i emulatorn kan den inte få tillgång till riktiga GPS-värden
        // Därför hårdkodas koordinaterna till slottet i Gamla stan så att MSR MAPS Web Services
        //kan testas.

        double latitude = 40.717;
        double longitude = -74;

        if (!myPosition.Location.IsUnknown)
        {
            latitude = myPosition.Location.Latitude;
            longitude = myPosition.Location.Longitude;
        }

        myTerraService.TerraServiceSoapClient client = new myTerraService.TerraServiceSoapClient();

        client.ConvertLonLatPtToNearestPlaceCompleted += new EventHandler<myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs>(client_ConvertLonLatPtToNearestPlaceCompleted);

        client.ConvertLonLatPtToNearestPlaceAsync(new myTerraService.LonLatPt { Lat = latitude, Lon = longitude });
    }

    void client_ConvertLonLatPtToNearestPlaceCompleted(object sender, myTerraService.ConvertLonLatPtToNearestPlaceCompletedEventArgs e)
    {
        location = e.Result;

        //throw new NotImplementedException();
    }


    private void AppBar_Cancel_Click(object sender, EventArgs e)
    {
        navigateBack();
    }

    private void AppBar_Save_Click(object sender, EventArgs e)
    { // spara en ny anteckning

        if (location.Trim().Length == 0)
        {
            location = "Okänd";
        }

        navigateBack();

    }
    private void navigateBack()
    {
        NavigationService.Navigate(new Uri("/secret;component/NotesMainPage.xaml", UriKind.Relative));
    }

    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        editTextBox.Focus();

    }
}
}
Muirhead answered 5/11, 2012 at 17:22 Comment(3)
is 'enter code here' part of it?Elidaelidad
Does the partial class have any other parts?Pile
no "enter code here" is not part of it. Its Partial Class by Default, im really new and are following a tutorial and implementing it into my own application though i have done exactly the same i get these errors?Muirhead
D
16

You are creating a partial class, so you probably have these members defined in another source file for your partial class.

You may look at the solution explorer, find that source file and either remove it from there or you may remove these members from your current partial class.

You may see: Partial Classes and Methods (C# Programming Guide)

To search for the other source file containing the partial class, right click on the Class Name AddPage and select Go to Definition. You will see multiple results in Find Symbol result window in visual studio.

Deduction answered 5/11, 2012 at 17:25 Comment(2)
i found that another c# file had the same names yet when i change them to their respective names The other files changes its names too? when i write them manually and dont use the option to reference and change the names the InitialiseComponents and editTextBox does not exist in the current contextMuirhead
this solution worked for me . Go to Definition -> multiple results in find result window .Confabulation
N
2

Check for another partial class in which you've already defined the AddPage() constructor or PhoneApplicationPage_Loaded() methods. You can achieve this by Ctrl+F and searching the solution for the method signatures:

public AddPage()

and

PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
Narcoanalysis answered 5/11, 2012 at 17:25 Comment(2)
It just shows the partial Addpage and the public Addpage im not entirely sure what to do because i get alot of other errors when removing on or the other? public partial class AddPage : PhoneApplicationPage { public AddPage()Muirhead
I would recommend you post both partial classes in your original question (just update/edit the original question).Narcoanalysis
V
0

I had something very similar recently, and it turned out that when importing existing code files I had imported the obj directory itself! visual studio screen shot

This directory contained, for example, the auto-generated (and automatically imported) MainWindow.g.i.cs file. So I was effectively including the same partial class definition twice, hence the "already defined" errors.

How this help someone else!

Voleta answered 17/4, 2014 at 8:39 Comment(0)
C
0

i had a project where i opened the main program.cs in notepad++, made some edits and did a "save as" to make a copy of the file in the same folder. i later opened the same project in visual studio and got this same error when trying to compile. i just had to exclude the files i created from making a copy from the project by right clicking on the problem file and selecting "exclude from project". did a build and viola! the copy was still in the folder just not being included in the build. screen shot of excluded files

Cyclic answered 6/2, 2019 at 4:25 Comment(0)
I
0

In my case the reason of this error was finally as simple as this. I added a new DB table to my EDMX in my DB project. I accidentally ticked the box for generation of class with methods (but these were already generated in the project). The EDMX file after this contained two similarly named classes AB.Context.tt and AB.xxx.Context.tt and both contained the same methods. As the classes were partial the mentioned error arose.

The solution was to remove accidentally and freshly added secondary AB.xxx.Contex.tt file and rebuild the project.

Interleaf answered 18/12, 2019 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.