Library of RD.xml files for NativeAOT

Andrii Kurdiumov
3 min readFeb 5, 2022
All RD.xml files you need

I did not wrote for too long. I probably has to catch up with news, or put some interesting content on the table. But for now I have only small announcement.

Problem

Based on my experience with compiling and testing applications, I notice that most of the time is spent on compiling was runtime crashes due to missing metadata for type here, method there. That’s either fixed by using more AOT friendly patterns, or if application is heavy user of reflection, you just add necessary entry to RD.xml file.

Other problem which I think also worth mentioning. If somebody wants to annotate their application, it requires either go with long loop: compile, run, crash, modify Rd.xml. Repeat as necessary. Other way is to find sample online, and then modify as you see fit. If you just want test water with NativeAOT, option “as you see fit” is quite cumbersome. You have to learn how to use NativeAOT, you potentially have to adjust your code. You have to understand how to plug rd.xml, find samples, etc. It is already complicated, so long tweaking loop sounds unappealing.

Other problem is all samples for RD.xml files and different libraries are scattered across internet. There’s not a lot of public examples on the internet, and you still have to actively look for them.

I think there should be a better way.

Proposed solution

I propose a solution which is similar to what TypeScript has with Javascript libraries. Create NativeAOT version of DefinitelyTyped. Community maintained repository of snippets which can be copied to your project without modifications so developers have to tweak only code of his app, and annotate types of his own app and not libraries which he using.

Example

Typical project right now consists of single RD.xml file where all types/assemblies dumped.

<!-- Every type and your friend's types goes here -->
<RdXmlFile Include="rd.xml" />

I propose to have single RD.xml file for each Nuget package. So if your application is using, for example, Avalonia and Sqlite using EF Core you will have following directives:

<!-- App specific file -->
<RdXmlFile Include="rd.xml" />
<!-- Community maintained files -->
<RdXmlFile Include="Avalonia.rd.xml" />
<RdXmlFile Include="Microsoft.EntityFrameworkCore.rd.xml" />
<RdXmlFile Include="Microsoft.EntityFrameworkCore.Sqlite.rd.xml" />

Let’s say you have simple password manager written in WinForms and again using Sqlite over EF Core.

<!-- App specific file -->
<RdXmlFile Include="rd.xml" />
<!-- Community maintained files -->
<RdXmlFile Include="System.Windows.Forms.rd.xml" />
<RdXmlFile Include="Microsoft.EntityFrameworkCore.rd.xml" />
<RdXmlFile Include="Microsoft.EntityFrameworkCore.Sqlite.rd.xml" />

Obviously this is not perfect solution. For some tech, like FSharp and EF Core would be problematic to write perfect RD.xml files which can be re-used. You probably still have to comment/uncomment content in these files.

Also when ILC starts understanding ILink XML file format, the need for this repository may lessen, since you can contribute these kind of definitions directly to library. On the other hand, we can have maintainers who do not care about trimming scenarios, so they would be reluctant to accept changes. Such centralized repository can provide a way how to use such libraries without too much of a problem.

Code

Not a lot of samples. But I have to start somewhere.

Call to action

If you want your application to start faster, and use less memory — try NativeAOT. If you have issues, file them to Dotnet repository. NativeAOT-LLVM also can compile small apps. Please try.

If you have RD.xml file for libraries not in RdXmlLibrary, please contribute! If you find issue, missing types in RdXmlLibrary, please contribute!

--

--

Andrii Kurdiumov

Math lover, lost in the woods of software development