Take the 2-minute tour ×

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
I'll give +1 since you are correct, but there are advantages to wrapping 3rd party libraries. If you are providing a library to be used by an application (especially external-facing), you don't want your users to care about the implementation details of your library. In this case, it is better to abstract the referenced library away and control their access to your system through a wrapper. I agree, this isn't always necessary, but there are definitive times when you want to do this. –  Jordan Parmer Apr 24 '12 at 21:57
add comment

Your Answer


