The web server of my hosting company complains that the class is not marked as [Serializable].
When I run it on my local host, it works fine, no problem. As soon as I upload it to the server, it asks it to serialize it?
Class Example:
public class Notification { public string Message { get; set; } public NotificationType NotificationType { get; set; } public static Notification CreateSuccessNotification(string message) { return new Notification { Message = message, NotificationType = NotificationType.Success}; } public static Notification CreateErrorNotification(string message) { return new Notification { Message = message, NotificationType = NotificationType.Error }; } }
This is what I use in the base controller. This class is stored in TempData when redirecting to another method, could this be the reason? But still, why on the server, and not on my local computer?
public abstract class BaseController : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { _notifications = TempData["Notifications"] == null ? new List<Notification>() : (List<Notification>)TempData["Notifications"]; _model = TempData["Model"]; base.OnActionExecuting(filterContext); } protected override void OnResultExecuting(ResultExecutingContext filterContext) { if (filterContext.Result is RedirectToRouteResult) { if (_model != null) TempData["Model"] = _model; if (_notifications.Count > 0) TempData["Notifications"] = _notifications; } base.OnResultExecuting(filterContext); } }
The controller overriding this simply adds notifications and a model if necessary, and then redirects to another action.
source share