Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Compiler Error CS1929

Visual Studio 2008

Instance argument: cannot convert from 'typeA' to 'typeB'.

This error is generated when you try to invoke an extension method from a class that it does not extend. In the example shown here, the extension method is defined for the derived class A, but not for the base class B.

To correct this error

  • Create a new extension method for the type where you have to invoke it, or else move the call into an object of the type that the existing method extends.

The following code generates CS1928 and CS1929:

// cs1929.cs
using System.Linq;
    using System.Collections;

    static class Ext
    {
        public static void ExtMethod(this A a)
        {
        }
    }

    class A : B
    {
    }

    class B
    {
        static void Main()
        {
            B b = new B();
            b.ExtMethod(); // CS1929
        }
    }
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.