Mixing Service and Project References

I have a solution which has three layers: common, data, and business

The common layer defines objects that are be referenced and used by the other layers. The data layer contains data access code and the business layer contains business logic. Each layer contains multiple projects.

The data and business layers expose WCF services which have objects from the common layer as parameters. Both the data and business layers reference the common layer directly via project references.

The business layer references the data layer via a service reference. The service references are set to 'Reuse types in referenced assemblies' because there are multiple references to the data layer services in a single business layer project and each of the data layer services uses the same objects from the common layer.

I am writing unit tests for the business layer and I am continually getting errors like this: Value of type Common.ClassName cannot be converted to Common.ClassName. Type mismatch could be due to the mixing of a file reference with a project reference to assembly Common. Try replacing the file reference with a project reference.

It isn't a file reference, it is definitely a project reference. Looking here I see this item

To access a type defined in another assembly, the Visual Basic compiler must have a reference to that assembly. This must be a single, unambiguous reference that does not cause circular references among projects.

As far as I can tell I do not have any circular references so what other problems could be causing this error message and/or how can I prevent this wasting so much of my time clicking on update service reference and hoping that this time it will work?

Note that I don't get a choice about this architecture, it is imposed by our software architect.

The environment is Windows 8 with Visual Studio 2012.


Because your business layer references the data layer via service reference and the data layer has a reference to your common layer you do in fact have a circular reference. This is done by the code gen in the background when you generate your wcf reference.

It is quite common when creating wcf services (for the first time) for programmers to run into this. The solution in your case is to ensure that any object (class, datacontract class etc) that is sent over the wire via WCF should be in the same assembly as the wcf interface file. To say this another way if your WCF Service function call or subroutine takes in or returns an object, that object should be in the same assembly (or in an assembly not referenced downstream of the service).

If you split them up you create a circular reference without realizing it because WCF auto-creates the client side versions of your server side data contracts automatically. You may be able to turn off this behavior but I don't know exactly how so I would suggest googling that. If these server side data contract files are in fact in the common class, then presto you have a circular reference because your business layer has the code generated versions of these files and also the reference to the common assembly.

For more information on this delve deeply into the generated code in your service reference. To do this you need to turn on the view all files function in visual studio solution explorer and then start digging into the code that is generated for you when you create that service reference.


 ? how to use auto generated typescript declaration files in separate project?
 ? Unable to find symbol 'Components'
 ? Visual Studio 2013 Typescript compiler isn't respecting '_references.ts' file
 ? Visual Studio 2013 Typescript compiler isn't respecting '_references.ts' file
 ? Visual Studio 2013 Typescript compiler isn't respecting '_references.ts' file
 ? How do I define the compilation file in 0.9.5
 ? How to initialize - AngularJs app with TypeScript
 ? import an existing typescript project into visual studio 2013
 ? Can't compile .d.ts TypeScript files in Visual Studio 2013
 ? VS2010 Post-build event, replace string in a file. Powershell?