Thursday, 12 August 2010

Data does not exist in the namespace Microsoft.Practices.EnterpriseLibrary

I started to build a new application this afternoon. It's nothing complicated, it just needs to read all the data for the forum on our Intranet and write it into flat files so we can archive it somewhere on our new improved Intranet. I fired up Visual Studio and knocked up a UI - basically it has a Start button and a number of progress bars. Switching to the code, I added a reference to the Enterprise Library 4.1 Data Access Application Block and wrote some code to read the data. Having got to the first point where I wanted to check that things were going more or less as I wanted them, I hit F5 to build and run the application.
The type or namespace name 'Data' does not exist in the namespace 'Microsoft.Practices.EnterpriseLibrary' (are you missing an assembly reference?)
Er, huh? I hit Rebuild with the same result. 
I checked that I'd added the block - yep, there it was in my project References. 
Rebuild. No joy. 
In the immortal words of Kenneth Williams, "stop messing about". I actually fired up Explorer and browsed to the DLL under my Program Files folder to ensure it was there.
Still no joy...

And then I had a flash of inspiration. The default .NET Framework version for the application was set to '.NET Framework 4.0 Client Profile' - what if that was causing a problem? That's caught me out before when I've been playing with MEF stuff. I changed it to the .NET Framework 4.0 full profile, hit Rebuild again and - success!

I solved my problem, but I'm sure I can't be the only one who's run into this one. It's trivial for me to solve because this application will only ever run on my laptop, but for someone who wants to use the Enterprise Library but also needs a minimal footprint when their app is installed, the two things become mutually incompatible. I can't help feeling that when you add a reference by browsing to a DLL, as I did, that Visual Studio should do a bit of inspection on the DLL and warn you if it's incompatible with the framework version you're currently using.


Mr Neily said...

You are a live saver, I had this same issue and decided to Google it before I smashed my head into my desk.

Thanks a bunch!

Glenn said...

Thanks for posting this. It may seem like a trivial little problem, but it sure had me frozen.

Mark said...

Thanks dude... helped!

James Koay said...

thank you my friend. I was scratching my head trying to figure out why it doesn't work when I have already included the block.

Dr. Charles Cavanaugh said...

Thanks a million! I was trying to run the parsingandscriptgen example program from the blog post getting to the crown jewels and was beating my head against the wall as to why it would not build in spite of the dlls being present!

Bentley Davis said...

This post really helped me out. As luck would have it my assemble was marked for full version of .net 4 but the app I was referencing my assembly from was marked for compact framework which made my assembly not appear in my app even though it was referenced.