I was trying to render a dynamic view into string.I got the idea from here and it is working well locally but on hosting I am getting the following error.My attempt is to convert the string to bytes for sending email
Value cannot be null. Parameter name: view
Controller
public ActionResult Index(int RegId)
    {
        try
        {
            var _mdlReceiptPdf = new ReceiptPdfVM
            {
                ...
                ...
            };
            string result = RazorViewToString.RenderRazorViewToString(this, Server.MapPath("~/Views/Shared/_Receipts.cshtml"), _mdlReceiptPdf);
            StringReader _sr = new StringReader(result);            
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
            return Json(ex.Message, JsonRequestBehavior.AllowGet);
        }          
    }
Util.cs
public static class RazorViewToString
    {
        public static string RenderRazorViewToString(this Controller controller, string viewName, object model)
        {
            controller.ViewData.Model = model;
            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
                var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString();
            }
        }
    }
 
     
     
    