You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Address SqlXml to CreateSqlReader dependency for assembly size #30912
I think it might be a good idea to move the XmlSqlBinaryReader type and support out of the private xml implementation possibly up into SqlClient assuming it's the only consumer. That would slim the main framework and remove this reflection dependency I think.
Might be worth filing an issue on IL Linker: the way this works in .NET Native is that trivial uses of reflection (especially these lightup patterns) are guaranteed to be evaluated at compile time.
We didn't need to mark things like this as roots in .NET Native because if the code that had the lightup was kept, so was the target of the lightup (thanks to the analysis).
IL Linker can only do a small subset of this analysis, but I think it should already understand typeof(Foo).GetMethod("Bar"). Something might be wrong if the extra roots in ILLinkTrim.xml are needed.
@MichalStrehovsky, part of the issue is that we do two passes with the linker: once as part of building the assembly (which is then published in the shared framework, the SDK, etc.) and once as part of publishing an app. We run it during the former to strip out things like internal/private consts, code in shared files where everything in the file isn't used by every assembly including that file, etc., in order to reduce the size of the shared framework. It's then run again during app publishing to do app-level trimming. In this case, CreateSqlReader is an internal method that's not referenced anywhere in System.Private.Xml.dll; it's only used by System.Data.Common.dll. So if it's not in the ILLinkTrim.xml file, the first linker pass that's only looking at the individual assembly trims it out.
Or is this because CoreFX build runs IL Linker on each assembly individually as part of the build when linker is allowed to trim everything that is not public and we need to prevent trimming at that stage?
Does IL Linker support multiple ILLinkTrim files? Maybe we could have two - one gets embedded in the assembly and gets used at both FX build and publish, and the other is only used as part of CoreFX build?
(Don't get me wrong, I hate these reflection lightups targeting privates more than anyone, but I'm not optimistic that we will be able to get rid of all of them.)
I'm not entirely convinced this one is even needed. SqlClient doesn't use this api It goes around it using the public api and if we can do that compatibly then I don't see why SqlXml needs private reflection or the binary xml reader in private xml either.
I've traced down what's going on and I don't see a good way to resolve it all. SqlXml will be passed a stream containing binary xml and the handler for that is internal inSystem.Private.Xml, XmlSqlBinaryReader. The reflection used in System.Data.Common is the way to create that type. Trying to lift XmlSqlBinaryReader out of the xml assembly will require copies of some of the xml internal support types (XmlValueConverter, XmlCharType among others) types a binary resources and localizable strings.
I think the attribute approach of identifying the dependencies so the linker can follow them intelligently is the best way to resolve this.
Activity
Wraith2 commentedon Sep 20, 2019
I think it might be a good idea to move the
XmlSqlBinaryReadertype and support out of the private xml implementation possibly up into SqlClient assuming it's the only consumer. That would slim the main framework and remove this reflection dependency I think.MichalStrehovsky commentedon Sep 20, 2019
Might be worth filing an issue on IL Linker: the way this works in .NET Native is that trivial uses of reflection (especially these lightup patterns) are guaranteed to be evaluated at compile time.
We didn't need to mark things like this as roots in .NET Native because if the code that had the lightup was kept, so was the target of the lightup (thanks to the analysis).
IL Linker can only do a small subset of this analysis, but I think it should already understand
typeof(Foo).GetMethod("Bar"). Something might be wrong if the extra roots in ILLinkTrim.xml are needed.stephentoub commentedon Sep 20, 2019
@MichalStrehovsky, part of the issue is that we do two passes with the linker: once as part of building the assembly (which is then published in the shared framework, the SDK, etc.) and once as part of publishing an app. We run it during the former to strip out things like internal/private consts, code in shared files where everything in the file isn't used by every assembly including that file, etc., in order to reduce the size of the shared framework. It's then run again during app publishing to do app-level trimming. In this case, CreateSqlReader is an internal method that's not referenced anywhere in System.Private.Xml.dll; it's only used by System.Data.Common.dll. So if it's not in the ILLinkTrim.xml file, the first linker pass that's only looking at the individual assembly trims it out.
MichalStrehovsky commentedon Sep 20, 2019
Or is this because CoreFX build runs IL Linker on each assembly individually as part of the build when linker is allowed to trim everything that is not public and we need to prevent trimming at that stage?
MichalStrehovsky commentedon Sep 20, 2019
Does IL Linker support multiple ILLinkTrim files? Maybe we could have two - one gets embedded in the assembly and gets used at both FX build and publish, and the other is only used as part of CoreFX build?
(Don't get me wrong, I hate these reflection lightups targeting privates more than anyone, but I'm not optimistic that we will be able to get rid of all of them.)
Wraith2 commentedon Sep 20, 2019
I'm not entirely convinced this one is even needed. SqlClient doesn't use this api It goes around it using the public api and if we can do that compatibly then I don't see why SqlXml needs private reflection or the binary xml reader in private xml either.
stephentoub commentedon Sep 20, 2019
If we can fix this by deleting stuff, that will make me happy.
Wraith2 commentedon Sep 26, 2019
I've traced down what's going on and I don't see a good way to resolve it all. SqlXml will be passed a stream containing binary xml and the handler for that is internal in
System.Private.Xml,XmlSqlBinaryReader. The reflection used in System.Data.Common is the way to create that type. Trying to liftXmlSqlBinaryReaderout of the xml assembly will require copies of some of the xml internal support types (XmlValueConverter, XmlCharType among others) types a binary resources and localizable strings.I think the attribute approach of identifying the dependencies so the linker can follow them intelligently is the best way to resolve this.
stephentoub commentedon Dec 6, 2019
@Wraith2, thanks for investigating.
Strip the ILLinkTrim.xml file from System.Private.Xml (#35547)