C#C
C#2y ago
Sekoree

✅ Trimming/NativeAOT preserve specific constructor(s) in ClassLibrary

Hi,
I'm a bit stuck with a trimming issue.
I basically have a shared project that has an abstract base class that other components can implement with a constructor that has some parameters.
Additionally it has a management class that handles creation of these components implementing that base class.
I use the
Activator
class to create instances of these components (which is the issue here I guess).
Is there any way to tell it not to remove the constructor on those components (and I guess that base class)?
Using and rd.xml worked once, now not anymore and idk why, but telling it to not trim those libraries entirely wouldn't be nice either.
Is there any way to define this from the shared project to apply to other libraries that implement that base class too?
(Also open to suggestions to not have to use this (static "Create" method in a base Interface maybe(?))

The implementations look like this:
The method that creates the objects: https://github.com/vocawaves/Manager/blob/2fcde9b4f24a2eb551aa11671a808c99fc64de39/Manager.Shared/ComponentManager.cs#L20
One of the Components:
https://github.com/vocawaves/Manager/blob/2fcde9b4f24a2eb551aa11671a808c99fc64de39/Manager.SimplePlayer/MediaPlayer.cs#L49
The base class:
https://github.com/vocawaves/Manager/blob/2fcde9b4f24a2eb551aa11671a808c99fc64de39/Manager.Shared/Interfaces/General/ManagerComponent.cs#L51
Was this page helpful?