Fix your code:
public string EncryptData(string data2Encrypt,string publicPath)
{
string retVal = null;
string publicpath = System.Web.HttpContext.Current.Server.MapPath(publicPath);
StreamReader reader = new StreamReader(publicpath);
string publicOnlyKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicOnlyKeyXML);
reader.Close();
try
{
byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data2Encrypt);
byte[] cipherbytes = rsa.Encrypt(plainbytes, false);
retVal = Convert.ToBase64String(cipherbytes);
}
catch (Exception ex)
{
}
return retVal;
}
A method that returns a string must return a string. In your case if an exception would have occurred there would have been no appropriate return statement.
It's good practice to have only one point of exit in a non void method and it should be the last statement in the method to avoid unreachable code warnings.
Cheers!