Home - Programming - "The type or namespace name 'Oracle' could not be found"

It's been really busy lately, and it's been a while since I've posted, but I wasted an entire day on this, no thanks to Microsoft whose FAQs had NOTHING about this roadblock, which as it turned out had a really simple solution.

I'm introducing Oracle support into a C#.NET, Visual Studio, highly configurable, multi-database solution. I used the Nu-Get Package Manager to pull the odp.net.managed package down, added a reference in each project in my solution that needed it, created a new class, added "using Oracle.DataAccess;" and "using Oracle.DataAccess.Client;", wrote the code instantiating and using the various Oracle data access objects I needed, then tried to do a build.

And got this message: "The type or namespace name 'Oracle' could not be found (are you missing a using directive or an assembly reference?)"

Normally that's something you see if you didn't properly add the assembly references in your project properties, but in this case this message seemed to be coming out of nowhere.

Here's what I forgot: This message doesn't necessarily mean you didn't add the proper references in your project configuration. It can also mean it was either unable to find the assembly at compile time or -- and this is key -- couldn't load it. Assemblies have version numbers, and if your project is targeting an older .NET version number, it will not load assemblies generated with later versions of .NET.

I finally came across an unrelated article about .NET versions, and it clicked.

BEFORE YOU PROCEED, save off a copy of your project directory tree. I don't want to be responsible for anyone jacking up their project. Code safe or find a different profession, y'know?

Okay, so you've backed up your project. I went back to Visual Studio, right-clicked each project in the solution, clicked properties, and selected "Application". The "Target Framework" for this project, which has been around a while, was ".NET 2.0". The assemblies I was attempting to work with were far more recent than that, so I selected the best fit version for my projects, which in this case, as of October 18th, 2015, was .NET 4.5. I also could have selected 4.5.1, but my gut was telling me to go one step back first, then I could change it if it didn't work out.

And VOILA. It compiled.

You're welcome.


Todd Grigsby