# ObjectInstantiationException with regards to object names in containers

**URL:** <https://discuss.gradle.org/t/objectinstantiationexception-with-regards-to-object-names-in-containers/45565>\
**Category:** Help/Discuss\
**Created:** [May 10, 2023, 10:39pm UTC](https://discuss.gradle.org/t/objectinstantiationexception-with-regards-to-object-names-in-containers/45565 "2023-05-10T22:39:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelvSYC](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kelvSYC](https://discuss.gradle.org/u/kelvSYC)\
**Post date:** [May 10, 2023, 10:39pm UTC](https://discuss.gradle.org/t/objectinstantiationexception-with-regards-to-object-names-in-containers/45565/1 "2023-05-10T22:39:46Z")

</div>

Suppose I have my own custom classes like so:

```gradle
interface MyInterface : Named {
    // ...
}

abstract class MyClass @Inject constructor(private val providers: ProviderFactory) : MyInterface {
    // ...
}

```

Now, suppose I have this:

```gradle
abstract class MyExtension @Inject constructor(private val objects: ObjectFactory) {
    val container = objects.polymorphicDomainObjectContainer(MyInterface::class.java)
    
    init {
        container.registerBinding(MyClass::class.java, MyClass::class.java)
    }
}

```

If I have in my code something like so:

```gradle
configure<MyExtension> {
    container.register<MyClass>("foo")
}

```

Registration is fine, but if I then do

```gradle
the<MyExtension>().container.named("foo").get()

```

I seem to get an `ObjectInstantiationException` relating to `MyClass`, relating to its constructor (It’s a `GenericSignatureFormatError`). It appears that Gradle does not normally extend `MyClass` with an implementation of the `Named` portion therein; how should I fix this issue? Can I do so without manually implementing `Named`?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 11, 2023, 7:41am UTC](https://discuss.gradle.org/t/objectinstantiationexception-with-regards-to-object-names-in-containers/45565/2 "2023-05-11T07:41:13Z")

</div>

You definitely should report that as error to Gradle.  
Somehow its class decorator generates a constructor signature that the JRE itself then cannot parse as it is invalid.  
This is definitely a Gradle bug.

In the meantime I suggest you either implement `Named` yourself or switch to field injection like

```plaintext
abstract class MyClass : MyInterface {
    @get:Inject
    abstract val providers: ProviderFactory
}

```
