Assembly Reference Error When Assembly Reference Is Correct

Ran into this one today…

Suppose you have a VS.NET console application (as I did) that references an assembly that in turn references System.Web. Guess what? It won’t compile. You’ll receive the following error, seeming to indicate that you haven’t referenced the correct assembly from your application project even though you have:

Error 102 The type or namespace name ‘[assembly name]’ could not be found (are you missing a using directive or an assembly reference?)

After a few minutes of banging my head on the desk, I figured that maybe there was a problem with one of the assemblies that my referenced assembly was referencing. Huh? Basically, my chain of references was as follows:

ConsoleApp -> Logging -> System.Web

My console app was referencing a logging assembly (which I wrote), which was then referencing System.Web (why my logging assembly was referencing System.Web is a topic for another post).

So, as a test, I figured I’d just add a reference to System.Web (in addition to the Logging reference) to my console app. Guess what? I couldn’t add System.Web. It didn’t appear in the list of available assemblies.

Add Reference

A few moments later I remembered something that I had seen a while ago about the target framework settings for VS.NET projects…there’s two .NET Framework 4 (and 3.5) options: one that includes all .NET assemblies (“.NET Framework 4”) and one that includes a subset of the .NET assemblies (“.NET Framework 4 Client Profile”).

Console App Properties

Since my project was a console app, VS.NET set the target framework to “.NET Framework 4 Client Profile”, which does not include System.Web (among others) as it is presumably more of a server-side type of assembly. Changing this setting “.NET Framework 4” made everything happy again, and without needing to reference System.Web from my console app project (which shouldn’t have been needed anyway).

Enjoy!

Advertisements

One thought on “Assembly Reference Error When Assembly Reference Is Correct

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s