Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0117 

'type' does not contain a definition for 'identifier'

This error occurs when a reference is made to a member that does not exist for the data type.

Several common situations can generate this error:

  • Calling a method that does not exist.

  • Using the Item property followed by an indexer.

  • Calling a qualified method when a class name and its enclosing namespace name are the same.

  • Calling an interface written in a language that supports static members inside interfaces.

The following sample generates CS0117.

// CS0117_1.cs
namespace MyNamespace
{
   public class MyClass
   {
      public static void Main()
      {
         int i;
         i = i.get();   // CS0117
      }
   }
}

Example

In this example, the Item property is used with an indexer. In C#, you can use a property or an indexer to access a member, but not both. The following sample generates CS0117.

// CS0117_2.cs
using System;
using System.Collections;
class Test
{
   public static void Main()
   {
      ArrayList al = new ArrayList();
      al.Add( new Test() );
      Console.WriteLine("{0}", al.Item[0]);   // CS0117
      Console.WriteLine("{0}", al[0]);   // OK
   }
}

CS0017 also occurs if you use a library written in a language that allows static members in interfaces, and you try to access the static member from C#.

// CS0117_3.jsl
// compile with: /target:library
public interface IMyJSharpInterface
{
   static int MyStaticMember = 0;
   void NonStaticMember();
}

The following sample generates CS0117.

// CS0117_4.cs
// compile with: /reference:CS0117_3.dll
class MyCSharpClass : IMyJSharpInterface
{
   public void NonStaticMember() {}

   public static void Main()
   {
      IMyJSharpInterface myObj = new MyCSharpClass();
      myObj.NonStaticMember();
      int i = myObj.MyStaticMember;   // CS0117
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft