Resolved Need help "Error Encountered an invalid type for a default value."

dimasfauzan300

New member
Joined
Sep 29, 2021
Messages
4
Programming Experience
1-3
Im using ASP .NET MVC4, i got some error when i access controller Error Encountered an Invalid value, but I can't locate that error, please help me, thank you

C#:
Server Error in '/' Application.

Encountered an invalid type for a default value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.FormatException: Encountered an invalid type for a default value.

Source Error:

[TABLE]
[TR]
[TD]An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.[/TD]
[/TR]
[/TABLE]

[B]Stack Trace:[/B]

[TABLE]
[TR]
[TD]
[FormatException: Encountered an invalid type for a default value.]
   System.Reflection.MdConstant.GetValue(MetadataImport scope, Int32 token, RuntimeTypeHandle fieldTypeHandle, Boolean raw) +12405251
   System.Reflection.RuntimeParameterInfo.GetDefaultValueInternal(Boolean raw) +151
   System.Reflection.RuntimeParameterInfo.GetDefaultValue(Boolean raw) +32
   System.Reflection.RuntimeParameterInfo.get_DefaultValue() +12
   System.Web.Mvc.ParameterInfoUtil.TryGetDefaultValue(ParameterInfo parameterInfo, Object& value) +18
   System.Web.Mvc.ReflectedParameterDescriptor.get_DefaultValue() +17
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +347
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +105
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState) +743
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +14
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +343
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +25
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +465
   System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +18
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +20
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +374
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +16
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +384
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +105
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163
[/TD]
[/TR]
[/TABLE]

[HR][/HR]
[B]Version Information:[/B] Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4330.0


Controller Code
C#:
[FilterConfig.CheckSessionTimeOut()]
        [FilterConfig.CheckAuthorizationAttribute]
        [HttpGet()]
        public ActionResult Index()
        {
            return View(getAccess(HasAccessType.AccessType.FULL));
        }



        [HttpPost()]
        //[ValidateAntiForgeryToken()]
        //[FilterConfig.CheckSessionTimeOut()]
        //[HasAccessType(HasAccessType.AccessType.READ)]
        public ActionResult getBoSample(int page = 1, int size = 20, string cari = "", DateTime start = new DateTime(), DateTime end = new DateTime(),  int filter = 1)
        {
            try
            {
                Pageable<BoSampleResponse> pageResponse = clsTrBoSampleCustomBL.findAll(page, size, cari, start, end, filter);
                return Json(clsAPI.CreateResult(true, pageResponse, string.Empty, string.Empty));
            }
            catch (Exception e)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return Json(clsAPI.CreateError(e));
            }
        }
 
Last edited by a moderator:
Please post your code as text in code tags, not as a screenshot.
 
In the future, please reply to the post, don't edit the original post like what is done on StackOverflow. Now my post #2 looks like I was on drugs talking about screenshots, when your now edited post #1 doesn't have screenshots anymore.

Anyway, I've edited your post #1 to fix the inline code tags (ICODE) into proper code tags (CODE).
 
Well, I'm assuming you are trying to access the getBoSample() action of the controller because it's the only one you presented that has default parameters. What parameters are your passing to that HTTP POST? It's kind of hard for us to try to figure out what is invalid if we have no idea what parameters you are passing in, an what parameters would end up using defaults.

Do you have any custom routes that go to that action? If so, does your custom route specify any parameters?
 
Im sorry i not following the rule, i sent parameter to that function
C#:
int page = 1, int size = 20, string cari = "", DateTime start = new DateTime(), DateTime end = new DateTime(),  int filter = 1
 
How did you send those parameters?
 
I would imagine that the values you are passing for start and end are not being interpreted as dates, which would explain why the error message mentions an invalid type. I would expect that those are being interpreted and evaluated as mathematical expressions, i.e. the number 9 divided by the number 30 and then divided by the number 2021. There is no literal date format in JavaScript so you will probably need to use new Date(2021, 9, 30).
 
I would imagine that the values you are passing for start and end are not being interpreted as dates, which would explain why the error message mentions an invalid type. I would expect that those are being interpreted and evaluated as mathematical expressions, i.e. the number 9 divided by the number 30 and then divided by the number 2021. There is no literal date format in JavaScript so you will probably need to use new Date(2021, 9, 30).
this date is parameter request from ajax, not for the response data, for now im confused the question is how i can parse the month to object class DateTime, and this error only show in my IDE, on my friend's IDE this error not shown
 

Latest posts

Back
Top Bottom