Method ‘XYZ’ cannot be reflected

We have consumed a third party web service and are trying to invoke it from an ASP.NET web application.
However when I instantiate the web service the following System.InvalidOperationException exception is thrown:

Method ‘ABC.XYZ’ can not be reflected.
Method ‘ABC.XYZ’ can not be reflected.
—> System.InvalidOperationException: The XML element ‘MyDoc’ from namespace‘ references
a method and a type. Change the
method’s message name using
WebMethodAttribute or change the
type’s root element using the

From what I can gather there appears to be some ambiguity between a method and a type in the web service.
Can anyone clarify the probably cause of this exception and is there anything I can do to rectify this or should I just go to the web service owners to rectify?

Edit: Visual Studio 2008 has created the proxy class. Unfortunately I can’t provide a link to the wsdl as it is a web service for a locally installed thrid party app.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I ran into the same problem earlier today.
The reason was – the class generated by Visual Studio and passed as a parameter into one of the methods did not have a default parameterless constructor. Once I have added it, the error had gone.

Method 2

It seems the problem is down to data type issues between VS and the web service that was written in Java.

Ultimately it was fixed by manually editing the class and schema files that were created by VS.

Method 3

I have come across the exact same problem when I was consuming a 3rd party web service. The problem in this instance was that the mustUndertand property in the reference file was looking for a Boolean, whereby the namespace property looked for a string.

By looking through the reference i was able to idenitfy the offending property and simply add “overrides” to the method signature.

Not ideal as any time you update the service you have to do this but I couldn’t find any other way around this.

To find the reference file select “all files” from the solution explorer

Hope this helps

Method 4

I’m guessing the wsdl emitted by or supplied with the service is not in a form that wsdl.exe or serviceutil can understand – can you post the wsdl or link to it?

how are you creating the proxy classes?

Also you might like to try and validate the wsdl against the wsdl schema to check its valid

Method 5

In my case I was getting a “method cannot be reflected” error due to that fact that in the class being returned by method, I had failed to expose a default parameter-less constructor.

I was working in VB.NET. In my return class I had declared a “New(..)” method that took a couple parameters (because that is how I wanted to use it in my code). But by doing so, I had supressed the default (hidden) parameterless New() constructor that VB adds behind the scenes. Apparently the web service handler requires that a parameterless constructor be available. As soon as I added back into my class a parameterless New() constructor, it all worked fine.

Method 6

I got the same message but mine was caused by a missing System.Runtime.Serialization.dll since I tried to run a 3.5 application on a machine with only .NET 2.0 installed.

Method 7

I had the same issue but I found that one of the WebMethod parameters has a member that is of type interface that is why VS could not serialise it. here is the exception when trying to download the disco file

System.InvalidOperationException: Cannot serialize member
of type ‘Leopard.Interfaces.IUser’, see inner exception for more
details. —> System.NotSupportedException: Cannot serialize member
of type Leopard.Interfaces.IUser because it is an interface.

Method 8

Old thread but I had a different issue, Maybe of help to someone. referenced dlls were mixed up between two versions on data layer and service layer that caused the problem.

Method 9

Another scenario where this error can happen: I simply had another web method with the same name (but different parameters)in my web service that slipped in during a code merge. After I deleted the old method it worked.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x