Custom visual element in DLL

I am currently implementing the new UIElements system.

When creating a custom element that uses the factory pattern. The source works just fine. However, when I create a DLL of the assembly I get the following error: “Element ‘type’ has no registered factory method”. Any ideas why this is happening?

Thanks in advance

Possibly code stripping?

Thanks for your reply!

The DLL is not created by Unity. And the factory pattern is visible inside a decompiler.
To my understanding, A DLL that is not built by Unity does not strip code (to my understanding).

I have a custom c# solution that gets build separately for this setup.

If your element is in or inherits from an element that is in the UnityEditor.UIElements namespace, this will not be included in any player build (but it will “seem” to work when in playmode inside the Editor). It might be why you see this error.

Let me better explain my setup.

I am creating a Unity editor plugin. For the deployment of the plugin, I want to create DLL’s of my source code. I have not created a player build.

When testing in my source code everything works just fine.
After creating a DLL of my source code I get the above-mentioned error.

You’re in uncharted waters, I’m afraid. We have not really tested this use case and, as an advanced use case, it’s not high on our priorities at the moment as we try to ship the toolkit. Not saying it’s not a valid use case, just can’t say when we can officially support it right now.

Some hints from the team point to a potential problem in how we look for assemblies when we try to find the correct element to instantiate when cloning a UXML asset. My suggestion would be to ship a shim text-based assembly on along-side of your dll-based assembly that contains the types you want to instantiate via UXML but just forwards them to the dll-types. Just something to try.

If you do find the solution (or the problem), I’d be curious to know. If it’s something simple we can fix on our end, we might be able to squeeze it in for the next release.

2 Likes

Same problem here. I will try to froward them and post if it works.
Any other solution so far?

2 Likes

Having the same problem here, I hope the next update fix this!

I’m watching this post too in case a solution presents. Definitely a feature I would like.

Hello all! Can one of you submit a bug report? We’d like to take a look at the issue and possibly solve it. Thanks in advance!

Hi, the case for this issue was submitted and passed to the developers: Unity Issue Tracker - No registered factory method error is thrown when class that inherit and extend an UIElement is used

The issue has been fixed in 2021.2.0a12