]> svcutil: Cannot import wsdl:binding 🌐:aligrant.com

svcutil: Cannot import wsdl:binding

Alastair Grant | Tuesday 1 February 2011

When trying to consume a web-service WSDL in Visual Studio 2010 I received an odd error, which also appeared when running the WSDL through "svcutil.exe".

The WSDL adds fine using the "old" Add Web Service method, or in Visual Studio 2005.

Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Object reference not set to an instance of an object.

There are a lot of topics on an exception being thrown, but these are generally namespaces or missing references. The Object reference not set is a horrible error that is the bane of my life as it could be anything. There is little on this combination of errors out there.

After some painstaking trial and error I narrowed it down to the XSD schema included in the <wsdl:types> section needed to have the attribute "elementFormDefault" specified at the root of the schema.

This resolved the error. I'm not sure exactly why this causes an error as it's not a required attribute in an XSD (as there are defaults) - and I have also seen other WSDL files that will import fine without this attribute specified. I assume it's down to complex types and namespaces - but I don't have the time (or need) to investigate further.

I hope this saves somebody else some time.

Breaking from the voyeuristic norms of the Internet, any comments can be made in private by contacting me.