Schravendeel Posted October 29, 2010 Posted October 29, 2010 Hello, The line "result._response = LoginResult.INVALID_REQUEST;" throws an Unreachable code detected warning. What am I doing wrong? [WebMethod] public LoginResponse Authenticate(string username, string passwordmd5){ LoginResponse result = new LoginResponse(); if (DataBaseManager.CheckIPBan(Context.Request.UserHostAddress)) { result._response = LoginResult.IP_BANNED; } else { if (MAINTENANCE_MODE) { result._response = LoginResult.MAINTENANCE_MODE; } else { result._response = LoginResult.INVALID_REQUEST; } } return result; } Quote
Leaders snarfblam Posted October 29, 2010 Leaders Posted October 29, 2010 Is MAINTENANCE_MODE a constant? If so, it would be the same as typing: if (true) { result._response = LoginResult.MAINTENANCE_MODE; } else { result._response = LoginResult.INVALID_REQUEST; } The compiler is just clever enough to realize that only one block of the if statement can ever be executed. The other block is unreachable. One alternative would be to define a symbol used for conditional compilation. [WebMethod] [color="Blue"]#define MAINTENANCE[/color] // Omit for non-maintenance build public LoginResponse Authenticate(string username, string passwordmd5){ LoginResponse result = new LoginResponse(); if (DataBaseManager.CheckIPBan(Context.Request.UserHostAddress)) { result._response = LoginResult.IP_BANNED; } else { [color="Blue"]#if(MAINTENANCE)[/color] result._response = LoginResult.MAINTENANCE_MODE; [color="Blue"]#else[/color] result._response = LoginResult.INVALID_REQUEST; [color="Blue"]#endif[/color] } return result; } Another alternative would be to suppress the warning for the code in question. Quote [sIGPIC]e[/sIGPIC]
Schravendeel Posted October 30, 2010 Author Posted October 30, 2010 Thank you! So, the C# compiler is a lot smarter that the VB compiler. Thanks for your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.