Wednesday, July 14, 2010

Type is Not Defined in Visual Studio 2010

I work for the University of Advancing Technology and as the name implies we (IT) ought to to be using advancing technologies. It's a little hard to do when we have so many legacy applications to maintain and expand. It took us a years just to move from VS 2003 to VS 2008 (.Net 1.1 to .Net 2.0+) However, one of my projects required using .Net 4.0 and Visual Studio 2010.

In this project I had to create a WCF service and a Windows service. To be used as testing grounds I also added aWindows Forms project to my solution as well.

My first task was to create the WCF service. To my biggest surprise that went pretty smoothly even though I had to reference a code library written in VS 2008 using .NET 3.5. To test my service, however, I wanted to use the Windows Forms project. There I added reference to that same code library I used in my WCF service. And that's where the problems began. For some reason creating an instance of an object from that code library was throwing error: Type 'myobject' is not defined. Interestingly that error only appeared when I tried to compile the project.

I tried the obvious, deleted then readded the reference, opened and closed my project, restarted Visual Studio, restarted the computer. Nothing. Same error.

Then I decided that perhaps I should look at the warnings as well. And one of the warnings game me a clue: The referenced assembly could not be resolved because it has a dependency on "system.Data.Oracleclient, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". I am not using Oracle but my middle tier, the code library I am trying to reference uses the Microsoft.Practices.EnterpriseLibrary libraries. It obviously has references to the aforementioned  Oracleclient.

After searching a little I found the solution. I had to have my project reference the full .Net 4.0 framework not only its client profile.

Open the project properties by right-clicking the project file then selecting Properties. On the left side click on Compile.

On this window click on Advanced Compile Options. On the bottom of that screen change the Target Framework to .NET Framework 4.

So it appears that WCF projects automatically use the full .NET Framework and Windows forms and Windows Services by default use the client framework only.

Good to know.

No comments:

Post a Comment