Question

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();

    }
}
}
Was it helpful?

Solution

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.

OTHER TIPS

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)

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!

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top