casbin / Casbin.NET

An authorization library that supports access control models like ACL, RBAC, ABAC in .NET (C#)
https://casbin.org
Apache License 2.0
1.13k stars 110 forks source link

TypeInitializationException when trying to reference a version of CsvHelper newer than v30.x #359

Closed ozeback closed 4 weeks ago

ozeback commented 4 weeks ago

We are using Casbin and CsvHelper in a .NET 8 application, and we are encountering null and TypeInitialization exceptions. There were some changes in the constructor of CsvConfiguration believed to be causing this. In v30 of CsvHelper, the constructor signature was CsvConfiguration(CultureInfo cultureInfo, Type? attributesType=null). In newer versions, the signature has been changed slightly and marked obsolete, CsvConfiguration(CultureInfo cultureInfo, Type attributesType).

When an application references Casbin and explicitly references a newer version of CsvHelper, there isn't a compile-time error because the calling signature still matches an existing constructor in the newer CsvHelper (e.g. Casbin is essentially compiled with this call signature: CsvConfiguration(cultureInfo, null)). However, the CsvHelper constructor also removed the null check for attributesType, and so you encounter an error at runtime.

This can be resolved with Casbin recompiling with a newer version of CsvHelper as there is another constructor with just the CultureInfo argument. Otherwise, anyone wanting to use a newer version of CsvHelper along with Casbin can't and is stuck on v30 of CsvHelper.

casbin-bot commented 4 weeks ago

@sagilio @sociometry @AsakusaRinne

sagilio commented 4 weeks ago

Thank you for your feedback. CsvHelper has been upgraded in the PR https://github.com/casbin/Casbin.NET/pull/357 You can try version v2.8.0 to see if it can resolve this issue.

ozeback commented 4 weeks ago

That did the trick. Thanks!