# C# Extension method not found

**URL:** <https://discussions.unity.com/t/c-extension-method-not-found/97672>\
**Category:** Questions & Answers\
**Created:** [February 28, 2014, 5:03pm UTC](https://discussions.unity.com/t/c-extension-method-not-found/97672 "2014-02-28T17:03:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![perchik](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/perchik/32/586188_2.png) [@perchik](https://discussions.unity.com/u/perchik)\
**Post date:** [February 28, 2014, 5:03pm UTC](https://discussions.unity.com/t/c-extension-method-not-found/97672/1 "2014-02-28T17:03:22Z")

</div>

I’ve written an extension method for UnityEngine.Transform but Unity doesn’t like it. If I explicitly call the extension method, it works fine, but otherwise it doesn’t.

## **Extension:**

* * *

```
using UnityEngine;
using System.Collections;

namespace CustomExtensions
{
    public static class TransformExtender
    {
        public static UnityEngine.Transform FindRecursive
            (this UnityEngine.Transform t, string name)
        {
            return FindRecursive(name, t);
        }

        private static UnityEngine.Transform FindRecursive
            (string name, UnityEngine.Transform current)
        {
           //... Implementation of recursive search not relevant to the question...will post in comments if anyone cares.
           return null;
        }
    }
}

```

## **Usage:**

* * *

```
using CustomExtensions;
...

void Start(){
     Transform T = transform.FindRecursive("somegrandchild");
     Transform R = TransformExtender.FindRecursive(transform, "somegrandchild");
}

```

* * *

The first usage gives me the error:

**error CS1061: Type `UnityEngine.Transform` does not contain a definition for `FindRecursive` and no extension method `FindRecursive` of type `UnityEngine.Transform` could be found(are you missing a using directive or an assembly reference?)**

The second usage works fine. For what it’s worth, Visual Studio intellisense understands the extension. If I type _transform.F_ it gives me the three options “Find, FindChild, FindRecursive(extension)” but for some reason the unity compiler doesn’t like it.

Any ideas what I’m doing wrong?

## **UPDATE:**

So, I was playing with it some more and it turns out that it does indeed work _some_ of the time. In particular

Transform upperArm = transform.FindRecursive(“upper\_arm\_R”);

string joint = “upper\_arm\_R”;  
Transform upperArmB = transform.FindRecurisve(joint);

the first instance works, the second does not( throws the CS1061 error). I’m not sure why those would be different, but I believe the Extension is probably not the error…

_“Extension method that takes a string works fine with string literal, but fails with variable of type ‘string’”_  
Any thoughts?

---

<div class="post-metadata">

**Author:** ![huntsfromshadow](https://avatars.discourse-cdn.com/v4/letter/h/5daacb/32.png) [@huntsfromshadow](https://discussions.unity.com/u/huntsfromshadow)\
**Post date:** [February 28, 2014, 5:13pm UTC](https://discussions.unity.com/t/c-extension-method-not-found/97672/2 "2014-02-28T17:13:26Z")

</div>

It’s the namespace. Get rid of the namespace and it should work.

Also your second method doesn’t have a ‘this’ argument in it’s arguments.
