-
-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler Trim Warnings #4425
Comments
The reason that the data portal works against type I find it hard to imagine anyone actually does serialize arbitrary types anymore. Now that the only serializable types must implement However, I am not sure it would be a bad thing to do as you suggest and require At least this basic change to the data portal interface needs to occur for CSLA 9.0, because (as you say) it is a breaking change). I am kind of thinking we should do this:
And make the data portal require |
Yes, instead of That would force the annotations into user code but that's what would be required for trimming. I would guess the goal would be to make CSLA and CSLA.Xaml at least trim friendly with the proper annotations to ensure that the compiler keeps what needs to be kept. I believe we no longer use incompatible serializers like the https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/incompatibilities |
We may also want to explore the |
I'd like @kant2002 to give any insights too. |
I would prefer to not push this into user code. On the other hand, perhaps that's unavoidable, and the future of .NET is code full of attributes to deal with AOT and the linker. I also wonder if some of this might become less important if we implement #4359 with a generator to make all the data portal calls (at least appear) strongly typed. That issue wouldn't affect dynamic creation of instances based on a type, but would/will ensure that the data portal methods in a business class are invoked in a way that the compiler knows they are being invoked. |
@rockfordlhotka I state multiple times and will repeat again. I'm strongly against using I agree with assessment that Most of problems which I seen in already annotated code compares from
@Bowman74
One potential plan which we can have is for example start small and make sure that only client CSLA is properly trimmable. and server side would be later on.
One practical solution is to any interested person to try create prototype of it's idea, implement it. Find limitations, comeback to us and share findings. so we can discuss workarounds and specific limitations. I tihnk we are still in learning phase where each interested person don't have even "okay" solution. I almost sure we can do much better |
I agree with @kant2002 about a complete solution, it is a v10 thing that needs more research and time. However, as I understand it, if we do nothing right now then it means we don't support MAUI in v9, and I don't want that if there is any way to keep MAUI with a lower impact partial solution. |
@rockfordlhotka can we create sample, run it with and fix all issues on the end-user side? That way we can
Obviously that's bad solution since we may teach people bad habits and we should spend time on advocating not to annotate things when not needed. Did somebody try create MAUI as it is? |
@rockfordlhotka The modest change that you accepted today will fix if for MAUI just plain not running without the invasive changes we are discussing here. So we should be good for .Net MAUI in your next prerelease build based on my testing. I'll test it again when the next nuget is released to make 1000% sure. What we won't support is native AOT compiled code. Native AOT compiled code will fail if any trim warnings are present (suppressed or not). However, native AOT compilation isn't required to distribute MAUI binaries. https://learn.microsoft.com/en-us/dotnet/maui/deployment/nativeaot?view=net-maui-9.0 As far as changes to library user code, I feel this is similar to when Microsoft introduced async/await. If CSLA wanted to take advantage of the new pattern, it bubbled throughout CSLA's codebase. If anyone who used your library wanted to take advantage of it, it would bubble into their code as well. It's just the nature of async/await and these trimming annotations that then need to bubble like this. The good news is anyone who doesn't care about trimming can just ignore the warnings just like they could if they called into async/await code without awaiting. |
I updated the samples. Currently due to some inconsistent trim annotations it won't run on iOS, MacOS or Andriod. However, the changes that need to be made were quite modest and already accepted into main. From what I can see now, we won't need to do the full change just to get it to run but as per my above comment native AOT compilation will not work. |
OK, good. One important question first: Changing the data portal API either has to happen in 9.0 or 10.0. If I do it now (like today), does that unlock further AOT work for 9.x point releases? Or should the whole thing be deferred to v10? |
@rockfordlhotka |
I'm torn - bifurcating the user base isn't good. At the same time, if people are using netfx and never plan to become modern in their codebase, I can see an argument to let them continue building up tech debt. Hmm. Let's keep things simple - do it for all versions of .NET. |
Will do
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Rockford Lhotka ***@***.***>
Sent: Thursday, January 2, 2025 10:42:34 AM
To: MarimerLLC/csla ***@***.***>
Cc: Kevin E. Ford ***@***.***>; Mention ***@***.***>
Subject: Re: [MarimerLLC/csla] Compiler Trim Warnings (Issue #4425)
@rockfordlhotka<https://github.com/rockfordlhotka> To be honest I'm not sure sure. After Spanish class I'll implement it and see what we are in for. I just need to know, do you want me to change out the System.Object for all .Net versions with ICslaObject or just .Net versions 8+
I'm torn - bifurcating the user base isn't good. At the same time, if people are using netfx and never plan to become modern in their codebase, I can see an argument to let them continue building up tech debt.
Hmm.
Let's keep things simple - do it for all versions of .NET.
—
Reply to this email directly, view it on GitHub<#4425 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABBNMJWVUVZB5Y7ILMHFUWD2IV3AVAVCNFSM6AAAAABUPJO5RCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRYGEZTQMBWGM>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@rockfordlhotka @kant2002 An example of this is the There is an explanation here on this under Functionality incompatible with trimming where Microsoft states:
https://github.com/dotnet/docs/blob/main/docs/core/deploying/trimming/fixing-warnings.md For now I will use the following annotation, which is spreading like a virus...
As an aside, based on how we load data portal methods dynamically in some spots I suspect the ICslaObject will need more than just We also call into |
To save time later, please add a string to the resx and use the resource rather than hard coded English. |
@rockfordlhotka Here is an interesting one. In several places in the code we call Well that cascades into needing to decorate the Let's just say we do all that annotation and a user is using CLSA and wants to clear trim warnings. Every time a piece of their code calls I think you see where I'm going here.... BTW, |
I expected as much. I can see where parts of CSLA itself could/should be trimmed if not used - like DataMapper or something. But it is hard to see where the core rules engine or the user code defining domain types could be trimmed. If that could be trimmed then someone isn't using CSLA or isn't writing domain types properly. I come back to this core thing right now:
|
OK, sounds good. Now we know. When you do a new nuget build with that PR that was accepted yesterday I'll make sure it works with all MAUI platforms. My testing based on my machine says it will, but I want to make sure to test with the actual packages. BTW, |
@Bowman74 I notice that you mention that NativeAOT build would not work if any trim warning is present. I can say that not true, it a just that it very likely do not work but because trimmer get rid of some important code. If force trimmer to keep code using DynamicDependency then it will work. |
@kant2002 I think you may be splitting some hairs. :) I said it will fail. Removing code needed for the application to run is pretty much failing. The native AOT compilers are very aggressive. But yes, we could use As soon as we are running down the path of |
Discussed in #4424
Originally posted by Bowman74 January 1, 2025
@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
The text was updated successfully, but these errors were encountered: