Ошибки многопоточного выполнения, особенно условия состязания. Когда Вы не можете остановить систему (потому что ошибка уходит), вещи быстро жестко ведут себя.
Создайте привязку модели, переопределите BindModel, проверьте тип и сделайте то, что вам нужно.
public class MyModelBinder
: DefaultModelBinder {
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
if (HasGenericTypeBase(bindingContext.ModelType, typeof(MyType<>)) {
// do your thing
}
return base.BindModel(controllerContext, bindingContext);
}
}
Установите привязку модели по умолчанию в global.asax
protected void Application_Start() {
// Model Binder for My Type
ModelBinders.Binders.DefaultBinder = new MyModelBinder();
}
проверяет соответствие общей базы
private bool HasGenericTypeBase(Type type, Type genericType)
{
while (type != typeof(object))
{
if (type.IsGenericType && type.GetGenericTypeDefinition() == genericType) return true;
type = type.BaseType;
}
return false;
}