C# reference to type component claims it is defined in system, but it is not found

2k views Asked by At

I am developing an application (blank solution) to read, write ,and edit data in an access database file.

I created an OleDbConnection object and gave it a connection string that worked in another Console application solution.

However, when I open or close the connection, I get the error "Cs7069 reference to type component claims it is defined in system, but it is not found"

  OleDbConnection a = new OleDbConnection();
//given connection string
a.Open();
a.Close();

I get the error when I call the Open() and the Close() methods. The error happens at compile time not runtime. [Visual studio 2015]

I tried: Rebuilding the solution Changing a variety of references Cleaning then rebuilding the solution

Note: I have only one project in the solution

Please help, Thank you

1

There are 1 answers

6
Shorstok On

Let me do some guessing.

Are you building an UWP app? If so, you just cannot use OleDbConnection, there is only this .NET subset for you.

If no and your app is not UWP, then can you reproduce error by creating empty console project, adding System.Data to references and creating minimal program to reproduce, like:

class Program
{
    static void Main(string[] args)
    {
        using (var connection = new System.Data.OleDb.OleDbConnection{ConnectionString = ".. your connection string .."})
        {
            connection.Open();

            Console.WriteLine("DataSource: {0}, database: {1}",connection.DataSource, connection.Database);
        }         
    }
}

And last and least possible, this error also can be caused by you having multiple assemblies with names mimicking System.Data, but i bet that's not your case.