How do I avoid 'call is ambiguous...' error when writing static and non-static methods in C#?
.net, c#, static, thread-safety
Solution
If you're making a call from an instance (e.g. `requestVar.Approve()`), then no, you have to rename it. The static can be called by using `Request.Approve()` however.
Problem
I have a number of classes that represents business transaction calls: executing appropriate stored procedures. Now the looks like this: ``` public static class Request { public static void Approve(..) { using(connection) { command.Text = "EXEC [Approve] ,,"] command.ExecuteNonQuery(); } } } ``` And I want to make them more thread-safe: ``` public class Request { public static void Approve(..) { new Request().Approve(..); } internal void Approve(..) { using(connection) { command.Text = "EXEC [Approve] ,,"] command.ExecuteNonQuery(); } } } ``` But getting next error message: The call is ambiguous between the following methods or properties: 'MyNamespace.Request.Approve(..)' and 'MyNamespace.Request.Approve(..)' How can I force, mark that I'm calling non-static, instance method from static? Or I cannot do that without renaming one of the methods? Or moving static method to another class, etc