-
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
Add marking of types used in .config files #712
Comments
@onovotny, you should be able to get past these errors with the following: <ItemGroup>
<TrimmerRootAssembly Include="System" />
<TrimmerRootAssembly Include="System.Diagnostics.Tracing" />
</ItemGroup> See https://aka.ms/dotnet-illink for more info. Happy to help if you run into further issues. |
Two things -- that got through part of it. I'd ask how a library author can annotate their code so a user doesn't need to do that. Like can EventSource be decorated and ConfigurationManager, etc? Second, after including those, I get more errors from WPF internals -- and I thought WPF was supposed to be working by default
|
Currently we don't support a way to annotate libraries in such a way like .NET Native did - this gets complex in the general case where libraries might reflect over types depending on inputs from user code. We're taking a different approach and trying to be very clear up-front about what kinds of patterns are supported with linking - currently the answer is most reflection-based apps will require developer intervention, and if that's not feasible you might not want to link your app at this point. We did pick defaults that were conservative enough to make the most basic WPF apps (templates) work, but we don't catch cases when reflection is used internally and so real-life WPF apps will need extra roots. If you take the approach of rooting whole assemblies (using |
Seems like whatever assembly SystemXmlLinqHelper lives in should be in the defaults as it’s internal wpf machinery? |
I don’t expect anyone to know what AssebmlyHelper loads as that’s all private impl details. |
It looks like the assembly is In the longer term we would like to have a way for frameworks to communicate optional dependencies like these to the linker (so that users don't have to dig into implementation details like you mention...), but we don't want to go the same path that .NET Native went down - it's something we're thinking about. Hopefully the doc I linked sets the expectations appropriately for this version. |
The first problem hit here - that is the |
The first problem with the The second problem with the missing <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> Which contains a fully qualified type name This is something the linker should solve in some way. That said I tried this in a new WPF .NET Core app and VS doesn't generate this XML anymore, it now generates a type reference like Given that NuGetPackageExplorer is a .NET Core only app, it would be safe to change the beginning of <?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<section name="PackageExplorer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections> I verified that with this change the app runs just fine in non-trimmed mode. When trimmed with linker (using the latest build of linker) it now gets all the way to the above mentioned problem with |
@onovotny I've hit the same error recently when trying to publish NET Core WPF app. I started digging to find the root cause of this and I think I've found it. The issue is not that the WPF uses reflection for XElement, it's how it uses it. If you look at the source code you will find that XElement is decorated as such: [System.ComponentModel.TypeDescriptionProvider("MS.Internal.Xml.Linq.ComponentModel.XTypeDescriptionProvider`1[[System.Xml.Linq.XElement, System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],System.ComponentModel.TypeConverter")]
public class XElement : XContainer, IXmlSerializable
{
} This type descriptor is important for WPF and depends on it. However there is an issue here that I think the .NET Core team missed - the XElement is referred from System.Xml.Linq assembly The linker correctly notices the use of XElement and includes System.Private.Xml.Linq in the trimmed output, but omits System.Xml.Linq as it has no executable code in it. The way to fix at the moment it is to explicitly tell the linker that we want <ItemGroup>
<TrimmerRootAssembly Include="System.Xml.Linq" />
</ItemGroup> So in the end if we use any type reflection such as I hope this helps someone. |
Trimming WPF apps is currently not supported: dotnet/wpf#3811 |
@onovotny commented in https://github.com/dotnet/coreclr/issues/26196#issue-481363865:
@jeffschwMSFT commented in https://github.com/dotnet/coreclr/issues/26196#issuecomment-521819777:
The text was updated successfully, but these errors were encountered: