Ambiguous Reference error between two namespaces

前端 未结 3 1447
慢半拍i
慢半拍i 2021-01-15 15:38

I get this message while trying to run a webservice on the browser. Note that the source code is a windows file and can\'t be changed for my need.

Com

相关标签:
3条回答
  • 2021-01-15 16:08

    You can fully qualify the class name when you declare your variable.

    Don't do

    Message msg = new Message();
    

    Do:

    ThreeDSeekUtils.Message msg = new ThreeDSeekUtils.Message();
    
    0 讨论(0)
  • 2021-01-15 16:09

    One simple solution is to write your methods with the full namespace like:

    void WriteSoapMessage(MessageBinding messageBinding, ThreeDSeekUtils.Message message, bool soap12)
    
    0 讨论(0)
  • 2021-01-15 16:15

    You need to adjust the signature to specify the explicit namespace of the Message class:

    void WriteSoapMessage(MessageBinding messageBinding, 
        ThreeDSeekUtils.Message message, bool soap12)
    

    or

    void WriteSoapMessage(MessageBinding messageBinding, 
        System.Web.Services.Description.Message message, bool soap12)
    

    Whichever is appropriate. Another option is to alias your namespaces in the using block at the top of the class:

    using ThreeD = ThreeDSeekUtils;
    using ServicesDesc = System.Web.Services.Description;
    

    Then you could use the aliases in shorter form:

    void WriteSoapMessage(MessageBinding messageBinding, 
        ThreeD.Message message, bool soap12)
    

    or

    void WriteSoapMessage(MessageBinding messageBinding, 
        ServicesDesc.Message message, bool soap12)
    
    0 讨论(0)
提交回复
热议问题