Repository navigation
Remove DAM from design-time attributes - #98378
Conversation
I noticed these attributes were bringing in a lot of designer code in WinForms due to the DAM annotation. However, I don't think the DAM annotation is appropriate for attributes meant for design time. I would instead inspect the code using these attributes to get RUC, or find a different way to preserve the code.
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
|
Tagging subscribers to this area: @dotnet/area-system-componentmodel Issue DetailsI noticed these attributes were bringing in a lot of designer code in WinForms due to the DAM annotation. However, I don't think the DAM annotation is appropriate for attributes meant for design time. I would instead inspect the code using these attributes to get RUC, or find a different way to preserve the code.
|
|
@eerhardt @LakshanF @vitek-karas @sbomer I would appreciate your thoughts here When looking at WinForms I noticed that most of the designer stuff was being brought in by these attributes, which are meant for design-time-only. The existing codebase tried to make the retrieval methods trim-compatible by annotating these attributes. But I'm not sure that's right. Aside from the fact that it didn't work, and those retrieval methods are still RUC for other reasons, I don't think making those methods safe is the right answer. If the intention of design-time is to only run during build, not during publish, I would actually expect this stuff to produce warnings if it were ever being kept in a production app (i.e., an app where trimming is enabled). If the user wanted to preserve this stuff for production, I would expect they would use some other attribute or code to do so. This could technically be considered a breaking change, but since all the main usage points are RUC, I don't think it's meaningful. |
|
We had a bit of discussion on this in #49467 (comment). |
|
Just a note on making the app smaller - another consideration might be to completly remove these attributes during trimming. That would in itself "fix" the problem with the DAM, but we could/should change that as well I think. |
Yeah, that's another approach, but I thought this one was actually simpler. The current design implies that "EditorAttribute" and "DesignerAttribute" intend to preserve stuff in your app (due to the DAM annotation) -- I think that's backwards. I would expect most people would think the target code should be trimmed away |
|
Also @JeremyKuhne |
|
A dam question, what's DAM (pun intended)? :) A lot of designer attributes may required for the PropertyGrid control to function at the runtime... |
This is unfortunate. However, I don't think it changes the calculus that much. From what I can see, WinForms trimming is not viable if the designer stack is brought in. It's all fundamentally unsafe. That implies that DesignerAttribute and EditorAttribute alone can't be sufficient to root code. So it still seems to follow that we should remove DAM from these attributes. The only question is if PropertyGrid can somehow be made safe in another way, or if we will just have to annotate PropertyGrid as RUC. Edit: Looking at the traces... maybe we could keep EditorAttribute. DesignerAttribute is the real killer here. If we get rid of that, it might be good enough. |
|
I moved out from the Windows Forms team, @KlausLoeffelmann may be able to provide deeper insights. |
|
@agocke I believe that |
Yes, but I would consider this to be a niche case. The "only" thing to solve for your average WinForms LOB App is reading resource files and DataBinding. I am currently working on the side on a Prototype to make DataBinding type safe: As long as we have customers wire-up the binding definition for their Forms/UserControls at design-time, we know both the data source/property source and the data destination/property destination. And since we generate that I haven't looked into the resource topic, yet, though, but there should be a similar approach possible. |
Yeah, that's another alternative to making PropertyGrid RUC -- use a feature flag to remove the Editor-specific functionality. As long as that's an acceptable user experience, I think that's a good path forward. Broadly, I think the question in this PR is: do we expect every By removing the annotation on the above types, we basically say, "this attribute is not supported when trimming." It doesn't necessarily mean that the types can't be preserved or used in a different way, it just means that the given attributes won't be enough to keep the targets around. |
Makes perfect sense to me! |
It will likely break https://github.com/meziantou/Meziantou.Framework/blob/ba361873c94491e459c81862b4b9b6abee8189ac/src/Meziantou.AspNetCore.Components/GenericFormField.cs#L212 (the repo does have references to The upswing from doing this is probably worth the break. We just have to make a breaking change notice and explain the upswing. Alternatively we could strip the attribute under a feature switch. This way people can still opt into the old semantic. #92043 has the diff to apply because I already experimented with it in the past. But I hate suggesting this because I detest feature switches and I hate attribute stripping as well because they require careful emulation during F5 debug time that breaks down for unit testing... and attribute stripping cannot even be emulated. |
|
Thanks for the pointer, I agree it will break that use case. And I do agree that a breaking change doc is merited. However, overall, I think it's worth the change. The semantics "design time attributes are only meant for design time" seems like the right intent. The argument that would persuade me the other way is that EditorAttribute is not meant to be a design-time attribute. That may be true. All the docs seem to suggest that it's meant to be for design-time, but I don't see the situation as clear cut as it is for DesignerAttribute |
Especially for WinForms App, the definition of something being design-time or run-time is a bit fuzzy. After all, the WinForms Designer itself is actually running at the user's design time. What I mean is: Folks are using the WinForms Property Browser Control for an easy way to collect for example a large amount of settings data. I don't think that that is the most frequent usage, but it certainly happens. Those cases would be qualifying as using Design-time functionality at runtime, especially, when they are authoring custom type editors which are called for a certain type through the property browser at (then) runtime. I think, there are workarounds around this, which could be trimmable, but the worst case would be, that those kinds of apps would not be able to use a feature flag (at least in the first iteration) and would be excluded from trimming. |
|
Yup, to be clear I expect there will be many people who are taking advantage of designer functionality at runtime for a variety of different reasons. However, the scope of making everything built for design-time be compatible with trimming is... challenging, if it's even possible. I think those apps are fine as is and should continue working -- they just won't be compatible with trimming without modification. |
ILLink will at least warn on attempts to use the attribute type. Would you consider it good enough if we had ILC/analyzer support for this? @MichalStrehovsky I am in favor of the approach in this PR given the current limitations of attribute stripping. I think both approaches will require a feature switch to remove the code that reflects over the attributes. |
If the analyzer could warn about this, it would alleviate some of my concerns. I don't know if it's possible with the current attribute stripping design. And we'd still have a hole in reflection APIs that don't take the attribute type as a parameter (they just list all attributes). We'd need to mark those as trim-unsafe and that might be a hard to swallow pill. Maybe better to open a separate issue for those conversations. I don't know if there's a way to make these experiences good. It might be that this is a mechanism we need to use when retrofitting trimming into things designed before trimming because nothing else is possible. But we'd advise against using these mechanism in any new code and not spend time designing experiences around it. |
|
@eerhardt Anything else? |
I noticed these attributes were bringing in a lot of designer code in WinForms due to the DAM annotation. However, I don't think the DAM annotation is appropriate for attributes meant for design time. I would instead expect the code using these attributes to get RUC, or find a different way to preserve the code.