Question

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?

Was it helpful?

Solution

Yes, you have to add a reference to your executable because when you are creating your formator, .NET expects it to be of type Func<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 pass null as the formator.

OTHER TIPS

An assembly is only aware of its immediate references (such as your library), and does not recursively load the references of its references, so you will have to add the reference to your executable.

Your library can include a wrapper class that inherits from SQLiteDataReader to get around this, but I don't see any particular advantage of doing this other than if you really don't want the executable to have the extra reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top