I have a C# library which has System.Data.SQLite as a reference, and an executable (as a 2nd project) which uses the library.
In the library, I have a function which references a class in System.Data.SQLite (Specifically the SQLiteDataReader class):
public static IEnumerable<T> SQLiteFetch<T>(Func<SQLiteDataReader, T> formator, string connectionString, string query)
The library compiles properly, but not the executable which calls this function.
This comes up as an error on build, saying I “must add a reference to assembly ‘System.Data.SQLite'”. I get that it’s due to the IEnumerable, but why isn’t the reference forwarded through my library? Do I really have to add a reference to System.Data.SQLite in my executable as well?
Yes, you have to add a reference to your executable because when you are creating your
formator, .NET expects it to be of typeFunc<SQLiteDataReader, T>. And since your executable doesn’t have a reference to System.Data.SQLite, it doesn’t know how to deal with your formator. This is the case even if you passnullas the formator.