Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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;
       }

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...