Compiler error cs0229

This repository contains .NET Documentation. Contribute to dotnet/docs development by creating an account on GitHub.

Permalink

Cannot retrieve contributors at this time

description title ms.date f1_keywords helpviewer_keywords ms.assetid

Compiler Error CS0229

Compiler Error CS0229

07/20/2015

CS0229

CS0229

f1ff7e91-1243-4d36-b792-26ba69186f8f

Compiler Error CS0229

Ambiguity between ‘member1’ and ‘member2’

Members of different interfaces have the same name. If you want to keep the same names, you must qualify the names. For more information, see Interfaces.

[!NOTE]
In some cases, this ambiguity can be resolved by providing an explicit prefix to the identifier via a using alias.

Example

The following example generates CS0229:

// CS0229.cs  
  
interface IList  
{  
    int Count  
    {  
        get;  
        set;  
    }  
  
    void Counter();  
}  
  
interface ICounter  
{  
    double Count  
    {  
        get;  
        set;  
    }  
}  
  
interface IListCounter : IList, ICounter {}  
  
class MyClass  
{  
    void Test(IListCounter x)  
    {  
        x.Count = 1;  // CS0229  
        // Try one of the following lines instead:  
        // ((IList)x).Count = 1;  
        // or  
        // ((ICounter)x).Count = 1;  
    }  
  
    public static void Main() {}  
}  

I am trying to call a Property called Filter that returns the string of the filter that is applied on a Table on my access application.

My library is:

using AccessApi = Microsoft.Office.Interop.Access;

My code is:

AccessApi.Application ap = (AccessApi.Application)Marshal.GetActiveObject("Access.Application");

string filter = ap.Screen.ActiveDatasheet.Filter;

But then Ambiguity Error occurs. I think I should overload somehow the Method I want to use but I don’t know how.

Martijn Pieters's user avatar

asked Aug 19, 2019 at 7:12

Tsal Giorgos's user avatar

3

I had the same issue today. My problem was caused by an auto-generated file which is used by Xamarin. The file implemented and declared the same variables as from my code.
Check you solution for auto-generated files.

answered Nov 4, 2020 at 19:47

DerDave's user avatar

  • Remove From My Forums
  • Question

  • I tried to implement the following scenario in VC++ 2005 beta2: an object implements 2 interfaces, one defining a property get and the other defining a property set.
    This works perfectly well when implemented in C#. However, in C++, I get the compiler error message transcripted below.

    Here is the C++ source code:

    namespace NS
    {
     public interface class INamed
     {
     public:
      property String^ Name
      {
       String^ get();
      }
     };

     public interface class INameable
     {
     public:
      property String^ Name
      {
       void set(String^);
      }
     };

     public ref class NamedObject : public INamed, public INameable
     {
     private:
      String^ m_name;

     public:
      property String^ Name
      {
       virtual String^ get() = INamed::Name::get
       {
        return m_name;
       }

       virtual void set(String^ value) = INameable::Name::set
       {
        m_name = value;
       }
      }
     };
    }

    When I try to use my object in a C# program:


       NamedObject o = new NamedObject();
       String name = o.Name;
    }

    I get the following compiler error:
    error CS0229: Ambiguity between ‘NS.INamed.Name’ and ‘NS.INameable.Name’

    There should be no ambiguity since there is only one get and one set (and, as I mentionned before, the same code works in C#).

    Is there anything wrong with my code (I hope so !).

    Chris.

Answers

  • Chris: I just tried your example with a recent build of both the C++ and the C# compilers. Your code compiled without any error and when I extended it slightly it also executed correctly.

    So it looks as if you are seeing a Beta-2 bug that has since been fixed.

Background

Experiencing error building a project in Visual Studio.

Error Image

Error Message

  1. Error CS0229 Ambiguity between ‘_jobSummary’ and ‘_jobSummary’
  2. Error CS0121 The call is ambiguous between the following methods or properties: ‘ExecJobActionAsync(Func<DbConnection, Task<int>>)’ and ‘ExecJobActionAsync(Func<DbConnection, Task<int>>)’
  3. Error CS0229 Ambiguity between ‘IsEnabled’ and ‘IsEnabled’
  4. Error CS0229 Ambiguity between ‘IsRunning’ and ‘IsRunning’

Troubleshooting

After a full day’s work, realized that the source of the problem is that I had backed up one of the source code files before editing it.

Unfortunately, the backup file was placed in a folder underneath the project’s working directory.

Remediation

To correct please do one of the following :-

  1. Move the folders and files outside of the project’s working directory
  2. Explicitly exclude the folder or file from the project

Visual Studio .Net Project

Outline

  1. Choose the folders or files to exclude
    • Right click on your selection
    • From the drop-down menu, please choose Exclude

Image

Image – Exclude From Project ( Initiate )

Image – Exclude From Project ( Completed )

Review

Project

To review included and excluded files you can do the following :-

Outline

  1. Ensure that Solution Explorer is tailored to show all files
  2. Review each .csproj file

Image

Solution Explorer

Image – Show All Files

Project File ( .CSProj )

Image

Explain

  1. Upon reviewing the .csproj file we notice the following
    • A new ItemGroup
    • The Item is tagged with “Compile Remove

Summary

Please be careful where you place copied files as it might inadvertently be included in your project.

Eldarsuperstar

0 / 0 / 0

Регистрация: 07.12.2020

Сообщений: 13

1

Неоднозначность между переменными

11.02.2021, 15:50. Показов 4025. Ответов 3

Метки нет (Все метки)


C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
 
namespace Лабораторная_работа1_Линейный_поиск
{
    class Program
    {
        static int k; //кло-во элементов в массиве
        static int[] a = new int[10];// масиы
        static void Main(string[] args)
 
        {
            Console.Write("Ввести количество элементов: ");
            int k= Convert.ToInt32(Console.ReadLine());//из строчного в числовое значение
            for (int i = 0; i < k; i++)
            {
                Console.Write("Ввести элементы массива : ");
                a[i] = Convert.ToInt32(Console.ReadLine());
                Console.Write("  {0}", a[i]);
            }
            comparison();//линейный поиск
        }
        static void comparison()
        {
 
            Console.Write("Ввести элемент поиска: ");
            int x = Convert.ToInt32(Console.ReadLine());//из строчного в числовой тип
           
            int s = -1;
            Console.WriteLine("Линейный поиск:");
            for (int i = 0; i < k; i++)
            { 
                if (a[i] == x)    
                  s = i;
            }
            
            if (s>-1)
                Console.WriteLine("Номер элемента = {0}", s);
            else
                Console.WriteLine(" заданного элемента нет");
 
 
        }
 
 
    }
}

выводит ошибку с однозначностью переменных которые объявлены в static (a и k)

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Пора на C++?

369 / 263 / 99

Регистрация: 10.04.2020

Сообщений: 1,275

11.02.2021, 15:55

2

Цитата
Сообщение от Eldarsuperstar
Посмотреть сообщение

ошибку с однозначностью

Это что?



0



0 / 0 / 0

Регистрация: 07.12.2020

Сообщений: 13

11.02.2021, 15:58

 [ТС]

3

Ошибка CS0229 Неоднозначность между «Program.a» и «Program.a»



0



Пора на C++?

369 / 263 / 99

Регистрация: 10.04.2020

Сообщений: 1,275

11.02.2021, 16:01

4

Лучший ответ Сообщение было отмечено Eldarsuperstar как решение

Решение

Цитата
Сообщение от Eldarsuperstar
Посмотреть сообщение

Ошибка CS0229 Неоднозначность между «Program.a» и «Program.a»

Эта ошибка никак не относится к приведённому коду. Скорее всего, у вас что-то с файлами проекта.



0



Понравилась статья? Поделить с друзьями:
  • Compiler error cs0123
  • Compiler error cs0122
  • Compiler error cs0121
  • Compiler error cs0120
  • Compiler error cs0119