C# – Ambiguous Reference error during runtime compilation

asp.netcnet

I recently added some namespaces to my web.config file so that all of my aspx pages can reference various constants and enums without the need to add an import statement on each aspx page. Since adding this, we are now getting an error when trying to test an asmx web service. It appears that during the wsdl generation we get the following error:

CS0104: 'Message' is an ambiguous
reference between
'System.Web.Services.Description.Message'
and 'InsTech.ForeSight.Message'

While researching this, I found out that DefaultWsdlHelpGenerator.asmx is called during the runtime compilation and there is a method in there that has the following signature:

void WriteSoapMessage(MessageBinding messageBinding, Message message, bool soap12) {

We have an object defined in our namespace called Message which is causing the ambiguous reference since this web service file is not fully qualifying their message.

How can I go about resolving this without removing the namespaces from the web.config? We have our web services in another folder in our virtual directory so I tried adding a web.config that did a clear on the namespaces but that did not appear to work.

Any help would be appreciated.
Thanks
Kevin

Best Answer

You can use namespace aliases in your code and use that to differ between them:

using ourOwn=our.own.namespace;

And refer to your Message class as ourOwn.Message. That will avoid the collision.

Related Topic