-
Notifications
You must be signed in to change notification settings - Fork 127
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
Does illink walk through resource files? #2840
Comments
Trimmer doesn't see into resources. It sees them as binary blobs. I know that one way .NET can use to store "objects" in resources is binary serializer, which has lot of problems with trimming - not counting that it's obsolete. I don't know what WinForms uses in We intentionally didn't put much effort into this, since there are basically endless possibilities of which format the resource blob could use to serialize stuff. |
Also - design-time stuff should probably not care about trimming - as in, I can't see how we would get into a situation where design-time stuff runs against trimmed app. I vaguely remember that we thought about this in component model, but I don't remember the details. Maybe @eerhardt remembers? |
See #1878 for why this and other APIs in ComponentModel were annotated with In general, I just annotated the code in the assembly so the trimmer wouldn't warn. I didn't give consideration to "Design" or "runtime" code - it is code that is available to call, so it is annotated as best as it can be. |
Essentially I should assume that any typename from resources maybe not preserved, and I have to annotate this code with RUC. Correct? |
Yes, unless you can prove some other way that the Type will be preserved. Reading a type name from a file (like a resources file) and trying to find it isn't guaranteed to work. |
That's fine. Given that |
That would definitely be bad. I would be curious how widespread this is in WinForms (resource loading that is). For example, maybe we should consider a feature switch in this case - just like we've done for generic resource reading in BCL. I guess what I'm saying is that RUC is not the only solution :-). |
If you know all the types, you can add DynamicDependency attributes to the code to preserve the types. another approach is a linker extension that reads the resource files and marks the types. Maui uses those a decent amount. Yet another approach would be a code generator that generated a “factory” method to create all the types. The linker would see the type used in code and not trim the type. |
Personally I would vote for source generator... linker extensions are problematic and we should get rid of them over time if at all possible. |
code generator for ResX files possible out of scope, since that's require somehow teach designer and CodeDom source generator to use that |
Given this is a BinaryFormatter scenario, I think some work will have to be done around it either way. Based on the old obsoletion plan, this was supposed to happen in .NET 7 for WinForms. I don't know where those plans stand now. |
There no better plans then dotnet/winforms#6267 . |
Closing as no longer relevant. BinaryFormatter is still a problem and will need a solution outside the linker. |
I have this warning in WinForms
This is indication that Type name stored in resource file require
PublicParameterlessConstructor
to be useful. I have dilemma, either I annotate that code as unprovable and apply RUC on the method. Or if illink can look at aseembly resources and read type name and keep public parameterless constructors to that type, that maybe useful.The text was updated successfully, but these errors were encountered: