Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solution won't build because it can't convert from service generated type to my type

I have a WCF service project that builds fine, makes an accessible WSDL, and svcutil.exe generates no errors.

I have a "Service Manager" project that access that web service, and to which I have successfully added a Service Reference ABCService.

A third project holds all the POCO objects that I need to pass back and forth - decorated liberally with [DataContract] and [DataMember] attributes.

When I try to build the solution, I see that Reference.cs for the ABCService has methods like this (I have substituted (...) for the full namespaces for brevity):

    public (...).Thing SaveThing((...).Thing objThing) {
        return base.Channel.SaveThing(objThing);
    }

    public (...).myCollectionOfThing0mj5ZrAW GetThings() {
        return base.Channel.GetThings();
    }

The first method, that returns a single Thing, works fine - but I get an error for every MyCollection method:

Error 16 Argument 1: cannot convert from '(...).MyCollection<Thing>' to '(...).myCollectionOfThing0mj5ZrAW'

My collection class is decorated as you'd expect:

[CollectionDataContract]
public class MyCollection<T> : List<T> where T : BaseType
{
  //  ...
}

I have no idea why it's generating the funky "myCollectionOfThing0mj5ZrAW" name, or why the translation from one to the other is failing

EDIT 1: I have tried using

[CollectionDataContract(Name= "myCollection{0}", ItemName = "{0}")]

to decorate my collection class, and I get the same error but with updated names:

Error 12 Argument 1: cannot convert from '(...).myCollection<(...).Thing>' to '(...).myCollectionThing'

EDIT 2:

Despite having checked the "Reuse types in referenced assemblies", selected the radio button for "specified referenced assemblies", and checking the box next to my POCO assembly: Screenshot of reusing referenced assemblies

...the service reference is STILL being generated with unique class names:

enter image description here

like image 627
Scott Baker Avatar asked Dec 05 '25 16:12

Scott Baker


1 Answers

As suggested by @vesan & @RitchMelton in comments, it seems types are regenerated at client and you should reuse the DataContract.

If you are adding service reference, reuse the type in referenced assemblies by selecting radioreuse types in all references assemblies: enter image description here

Also note you might need to change collection type to System.Collection.Generic.List to prevent changing of List to Arrays/

If you are generating proxy using SvcUtil, you need to use /reference: to reuse DataContract assemblies while generating reference like:

svcutil /reference:YourDLL.dll http://localhost/YourService?wsdl

For more details on /refernce with SvcUtilrefer:

ServiceModel Metadata Utility Tool (Svcutil.exe)

svcutil exlude/reuse refrenced assemblies

like image 162
Pranav Singh Avatar answered Dec 08 '25 05:12

Pranav Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!