-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
.NET 7 AOT Compatibility #2089
Comments
I'm not sure if this is possible. https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/warnings/il3050 Nearly every method in CsvHelper needs It looks like you might just need to have the type declared somewhere in the system. In your case, try putting the type I'm looking into adding that method everywhere. |
Yeah... Pretty much every method in the system needs this added to it. Doesn't seem like the right way to do it. Make a note in the documentation on it instead or something. |
Thank you @JoshClose, I'll test your workaround today. Anyway, I think that the right way to solve the problem is to use code source generators and generate custom library code at compile time based on app code. |
Oh interesting. Do you have experience with source generators if I have questions? |
Unfortunately no.. I studied them one year ago but only for "academic" purposes. I studied some Microsoft docs to better understand the new implementations also for native libraries and here you can find how works the Microsoft implementation for |
Awesome thanks! I bet AOT will allow for all feature to work on iOS now too. |
Looks like I might be able to do a quick and dirty solution of just creating classes The better way to do it would be to do what I'll have to look into this more. |
Looks like using compiled lambda expressions was interpreted in AOT scenarios previously. I'm checking if that is still the case. dotnet/runtime#17973 |
They're still interpreted which means slower than reflection. The quick dirty solution will make it insanely slow for you. I will need to reimplement that entire library using reflection only (no expression trees). It looks like source generators work on netstandard2.0 though, so it'll go back to net461. I don't know if I want to keep 2 versions of the code though. I'll have to do some more digging to see if I can get away with just using source generators. |
The generators are only netstandard2.0 because they just run while compiling with Roslyn. The generator code is in another assembly and can take on any dependencies it wants, separate from the CsvHelper assembly. Taking a look at this https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/
I can't do source generators only. This will have to be another method, or a parameter passed into existing methods that enable it. Or maybe even a This will be a significantly large undertaking. |
It really seems a big work to do 😅 |
I successfully used CSVHelper work on native aot by using Demo code: public class CsvRecord
{
public string Exchange { get; set; }
public string Commodity { get; set; }
public string TradingRange { get; set; }
}
internal class Program
{
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvRecord))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Configuration.DefaultClassMap<CsvRecord>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Configuration.MemberMap<CsvRecord,string>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.RecordManager))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.RecordCreatorFactory))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.RecordHydrator))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.ExpressionManager))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.TypeConversion.StringConverter))]
static void Main(string[] args)
{
string csvString = """
Exchange,Commodity,TradingRange
GX,USD/JPY,0.01
GX,EUR/JPY,0.01
""";
StringReader stringReader = new StringReader(csvString);
CsvHelper.CsvReader csvReader = new CsvHelper.CsvReader(
stringReader,
System.Globalization.CultureInfo.InvariantCulture
);
var record = csvReader.GetRecords<CsvRecord>();
foreach (var r in record)
{
Console.WriteLine(r.Exchange);
Console.WriteLine(r.Commodity);
Console.WriteLine(r.TradingRange);
}
}
} I use these Attribute to able run CSVHelper at AOT mode. [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvRecord))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Configuration.DefaultClassMap<CsvRecord>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Configuration.MemberMap<CsvRecord,string>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.RecordManager))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.RecordCreatorFactory))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.RecordHydrator))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.Expressions.ExpressionManager))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CsvHelper.TypeConversion.StringConverter))] The main point: I hope this can help you. |
Is your feature request related to a problem? Please describe.
.NET 7 has been finally released in November 8th. With the new framework update Microsoft ships also the native AOT compilation feature.
For now this feature is supported only on console apps and with some limits explained here.
Is it possible that this library become one of the supported ones for AOT compilation?
Additional context
At the moment we simply try to convert one of our console app, that use
CsvHelper 29.0.0
from.net6.0
to.net7.0
adding also the new AOT property as in this sample:It seems that
CsvHelper
is not supported:The text was updated successfully, but these errors were encountered: