none
Method Name Conflict Issue RRS feed

  • Question

  • Hi,

    When I write bleow code, looks good while compiling. But getting called the other method as well once the execution of first method is finished.

    Source Code:

    1.

    [TestMethod]

    public void abc1()

    {

    }

    2.

    [TestMethod]

    public void ABC1()

    {

    }

    Above 2 methods are different, as C# supports the case sensitivity. But why it is getting called. Can Microsoft fix this problem in later versions.

    It is somewhat confusing and its easily can't find out.

    Thanks,

    Shankar Solunke.

    Thursday, May 19, 2016 10:08 AM

Answers

  • The original poster's code uses [TestMethod]. Perhaps those methods are being called by the Visual Studio unit test framework.

    Indeed, if I set up two methods like that and execute "mstest.exe /testcontainer:demo.dll /test:abc1", then mstest runs both abc1() and ABC1(). The /test option is documented as running each test whose name contains the specified substring, so the case-insensitive comparison seems reasonable.

    In contrast, if I select one of those tests from the Test View window of Visual Studio and choose Debug Selection, then it runs only the selected test and not the other one.

    I don't know what the original poster is using to run these tests, though.

    Wednesday, June 1, 2016 3:21 PM

All replies

  • I cannot see any problem.

    If I create two methods called abc1 and ABC1 (in the same class), and I call abc1() then only abc1() gets called!

    Can you provide the code you are using to actually call these methods? (Paste in code using the Insert Code Block icon - the one 2nd from the right that looks like a page with little <> arrows).


    Thursday, May 19, 2016 10:19 AM
  • Hi Shankar,

    Can I assume my counter-example pointed the way to an explanation of your issue?

    Did you resolve your issue some other way?

    Wednesday, June 1, 2016 9:38 AM
  • The original poster's code uses [TestMethod]. Perhaps those methods are being called by the Visual Studio unit test framework.

    Indeed, if I set up two methods like that and execute "mstest.exe /testcontainer:demo.dll /test:abc1", then mstest runs both abc1() and ABC1(). The /test option is documented as running each test whose name contains the specified substring, so the case-insensitive comparison seems reasonable.

    In contrast, if I select one of those tests from the Test View window of Visual Studio and choose Debug Selection, then it runs only the selected test and not the other one.

    I don't know what the original poster is using to run these tests, though.

    Wednesday, June 1, 2016 3:21 PM
  • Yes, I did wonder about those attributes and whether the OP was using some kind of automated testing (I'm not actually familiar with the Visual Studio unit test framework).

    How the methods are getting called is rather vital information omitted from the original question! Perhaps the OP can provide more details?

    Wednesday, June 1, 2016 3:29 PM