Replies: 1 comment 2 replies
-
I've created an issue based on this discussion, because at least some part of this has to happen in v9.0 because it will be a breaking change. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@rockfordlhotka
Currently we have suppressed many of the trim warnings in CSLA. The following are suppressed:
IL2026 IL2055 IL2057 IL2060 IL2070 IL2072 IL2075 IL21111 IL3050
I looked into what it would take to resolved them. Many of them cannot be fixed without re-thinking interfaces like
IDataPortalServer
'sUpdate
method's obj parameter. Right now the parameter isSystem.object
, something outside of our control.The problem is in DataPortal.cs (Csla.Server.DataPortal) that implements
IDataPortalServer
. It the implementation of theUpdate
method it calls intoCsla.Reflection.ServiceProviderMethodCaller.FindDataPortalMethod
passing in an objectType
to the targettype parameter. That parameter in theFindDataPortalMethod
method is decorated with:[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
Wherever that type comes from also has to be decorated. If we look back at the Update method we find this line where the type is gotten:
objectType = obj.GetType();
OK, so in order to clear this warning we need to make sure that obj, whatever it is, is similarly decorated. So we look back and find that obj is the
Update
method's parameter of typeSystem.object
. We can't decorate that.Three ways to fix come to mind. All three of these require
IBusinessObject
and all derived types to be annotated with theDynamicallyAccessedMembers
if on .Net 8+. This will require user code for business objects to also have annotations if they don't want the same warnings, which makes that they would have to tell the compiler not to get rid of all those apparently dead wood data portal methods.Here are my ideas on ways to fix:
IDataPortalServer's
Update method toIBusinessObject
fromSystem.Object
. Breaking change for anyone who created a custom implementation of any of these interfaces, ugh...IDataPortalServer
's interface to useIBusinessObject
on .Net 8+, all lower versions still useSystem.Object
. More backward compatible, only causes a potential issue when revving .Net version to 8+. Ugly code with lots more #ifs.IDataPortalServer
interface alone so parameter is stillSystem.Object
. In the Update method if .Net 8+ we check to see if the obj parameter is castable toIBusinessObject
. It not we throw some sort of invalid parameter exception. If it is of typeIBusinessObject
we cast it to that type and callGetType
on that, clearing the warning.There are other possible solutions like using
[DynamicDependency]
. Microsoft does not recommend this but it is a possibility.https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
Beta Was this translation helpful? Give feedback.
All reactions