views:

16

answers:

1

I have the following classes defined in an external assembly from a third-party vendor:

namespace ThirdParty.Vendor.Code
{
  [Serializable]
  [XmlInclude(typeof(Test1Data))]
  [XmlRoot(Namespace = "", IsNullable = false)]
  public abstract class DeviceTestData
  {
    protected DeviceTestData();
  }

  [Serializable]
  [XmlRoot(Namespace = "", IsNullable = false)]
  public class TestData : DeviceTestData
  {
    public TestData();

    public double DoubleValue { get; set; }
    [XmlIgnore]
    public bool DoubleValue ValueSpecified { get; set; }
  }
}

I've added this assembly as a reference to my WCF service called "TestService" so I can write service code that makes use of these types. That all works perfectly.

Now I have a second project to which I need to add a reference to TestService. Adding the reference works fine, but when I write code to use the referenced types and attempt to compile I get the following error:

The type or namespace name 'TestData' could not be found (are you missing a using directive or an assembly reference?)

So I added the vendor's DLL as a reference in the second project and a directive to use the namespace ThirdParty.Vendor.Code, but now I get:

Cannot implicitly convert type 'ThirdParty.Vendor.Code.TestData' to 'ServiceReference.DeviceTestData'

It seems that without the reference to the third-party DLL, the required classes don't get generated, but if I add the reference, they get referenced twice somehow. WTF?

Anyone got any suggestions for how to fix/work around this?

+1  A: 

When you generate the service reference, make sure you have the assembly holding the data contract already referenced, and select "Reuse types in referenced assemblies".

Philip Rieck
Tried that, still get "Cannot implicitly convert type..."
Ian Kemp