Empty DataContract Causes Misleading Error

Wednesday, February 17, 2010 / Posted by Luke Puplett /

After my last post on this subject you'd have thought I'd learnt a lesson but the error message and sheer coincidence of the error being about a class I happened to be working on at the time meant it took me 10 hours to unearth the problem.

After updating a service reference that had been left for some months, I received the following IDE warning:

Custom tool warning: Cannot import wsdl:portType

Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter

Error: Referenced type 'Steelcore.Spanware.QueryBlock, Steelcore.Spanware, Version=2.0.1.0, Culture=neutral, PublicKeyToken=80726da9f797f65e' with data contract name 'QueryBlock' in namespace 'http://schemas.evoq.co.uk/steelcore/2009/03/spanware' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.

Because I had just been adding new web methods that use QueryBlock, and because I am working in Visual Studio 2010 RC1 it was difficult to know if this was a genuine error, afterall, I'd not changed the Steelcore code for ages and it used to work.

Troubleshooting

I'll spare you the details on all the stuff I tried that didn't work. Getting to the bottom of it was a case of isolation.

To remove the local client project from the equation I created a new WCF Service app in Visual Studio, added the reference to my Steelcore library and configured the service with one web method/operation contract that takes the offending class QueryBlock as its sole argument. I then created a new client app, referenced Steelcore and the WCF service. This caused the same warning.

I then opened the Steelcore solution and commented out some of the DataMember attributes on the QueryBlock and rebuilt. Went back to my little test rig and rebuilt and updated the service references. Warning gone.

Obviously one of the types used in the now defunct DataMembers is causing the issue, probably my LooseTypedCriteria class, so I changed the WCF service to accept one of these as its sole argument and found the warning from SvcUtil was talking about Steelcore.Spanware.Criteria.

I commented out some of the DataMembers on Criteria and repeated the process. It all referenced fine, and so again, one of those members is using a class that SvcUtil doesn't like. I noticed one was an enum and then I recalled my enum DataContract problems.

Solution

Sure enough this enum had a DataContract but no DataMember attributes applied. This makes it effectively empty. As before, the solution was to remove the DataContract and let .NET figure out the contract automatically.

Labels: ,

1 comments:

Comment by Sebastian Schwarzbrunn on Thursday, April 04, 2013

Hello,

In my case it was caused by missing DataMember / EnumMember attributes. Setting them has solved the problem. Thank you very much for that help.

Post a Comment