The webserver on my hosting company keeps complaining that the class is not marked as [Serializable].
When i run it on my localhost it works fine, no problem. As soon as i upload it to the server it asks me to serialize it?
Example class:
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 };
}
}
That i use in a base controller. This class is stored in TempData when a redirect to another method occurs, can 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 one just adds the notifications and a model if needed and then to a redirect to another action.