Visual studio 2017 | Unable to get client context

I am trying to connect to sharepoint online site using console application in VS 2017 but everytime it returns 400 bad request.

Same code works as expected in VS 2013

   System.Security.SecureString securestring = new System.Security.SecureString();         foreach (char ch in password)             securestring.AppendChar(ch);         SharePointOnlineCredentials creds = new SharePointOnlineCredentials(userName, securestring);              using (var clientContext = new ClientContext(siteUrl))             {                 clientContext.Credentials = creds;                 Web web = clientContext.Site.RootWeb;                  clientContext.Load(web);                 clientContext.ExecuteQuery();             } 

Please help.