This is a migrated thread and some comments may be shown as answers.

RadScheduler using MVC 3.0

3 Answers 119 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Camilo Torres
Top achievements
Rank 1
Camilo Torres asked on 11 Nov 2011, 02:05 PM
Hi,

I have been trying a demo project (the zip file that I downloaded was named as 213914_radschedulerdemo.zip) posted by Telerik support in one of the Telerik forums. The demo uses MVC 2.0 and RadScheduler. The demo works fine when MVC 2.0 is used. But in our application we are using MVC 3.0 and need to use RadScheduler. Using the provided sample, I tried to modify it to use MVC 3.0 instead of MVC 2.0. But after making these changes I get following error:

"Object reference not set to an instance of an object."

in OnActionExecuting method that is used to deserialize Json. Following is the snapshot of Exception:

======================
System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=RadSchedulerDemo
  StackTrace:
       at RadSchedulerDemo.Helpers.JsonParameterFilterAttribute.OnActionExecuting(ActionExecutingContext filterContext) in D:\3 SecurePMS\RnD\213914_radschedulerdemo\RadSchedulerDemo\RadSchedulerDemo\Helpers\JsonParameterFilterAttribute.cs:line 44
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: 
============

Following are the changes that I have done in the code:
1. Changed .Net framework of project from 3.5 to 4.0
2. Replaced reference to System.Web.MVC (2.0) with 3.0 version. Updated <assemblies> in web.config.
3. Commented Authorize attribute in "ScheduleController.cs" and "SchedulerServiceController.cs" files to disable authentication.

Note: I am not able to find the forum from where I downloaded the demo and also not able to upload the updated solution.

Any help on this will be of great help.

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Camilo Torres
Top achievements
Rank 1
answered on 12 Nov 2011, 07:08 AM
Never mind, I resolved the issue.
For some reason when running the sample in MVC 3.0 the "HttpRequestBase.InputStream" position was at the end of stream. I modified the "OnActionExecuting" method to include following line before I read from this stream:

filterContext.HttpContext.Request.InputStream.Position = 0;

Following is the complete modified method for reference:
public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string contentType = filterContext.HttpContext.Request.ContentType;
 
            if (string.IsNullOrEmpty(contentType))
            {
                return;
            }
 
            if (!contentType.Contains("application/json"))
            {
                return;
            }
 
            Debug.Assert(Parameters.Length == TargetTypes.Length, "Parameters and TargetTypes must be the same length");
 
            string paramValue;
            filterContext.HttpContext.Request.InputStream.Position = 0;
            using (StreamReader reader = new StreamReader(filterContext.HttpContext.Request.InputStream))
            {
                paramValue = reader.ReadToEnd();
            }
 
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            IDictionary<string, object> rawResult = (IDictionary<string, object>)serializer.DeserializeObject(paramValue);
 
            for (int i = 0; i < Parameters.Length; i++)
            {
                Type t = serializer.GetType();
                MethodInfo deserializeMethod = t.GetMethod("ConvertToType", new[] { typeof(object) }).MakeGenericMethod(TargetTypes[i]);
 
                filterContext.ActionParameters[Parameters[i]] =
                    deserializeMethod.Invoke(serializer, new[] { rawResult[Parameters[i]] });
            }
        }

Hope this helps to someone out there.
Thanks.
0
Huy
Top achievements
Rank 1
answered on 16 Feb 2012, 04:48 AM
Thanks, I have same problem & now it resolved too.
So, I have another problem when I run that example in Local(Intranet inviroment) it run as well however when I public this host to run on the Internet invironment it have an issue as bellow:

ERROR MvcApplication Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'.
System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The call is ambiguous between the following methods or properties: 'System.IO.TextWriter.Write(string, params object[])' and 'System.IO.TextWriter.Write(char[])'
   at CallSite.Target(Closure , CallSite , HtmlTextWriter , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at ASP.views_shared_error_aspx.__RendererrorContent(HtmlTextWriter __w, Control parameterContainer) in d:\WaveFormSystem\Views\Shared\Error.aspx:line 8
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\WaveFormSystem\Views\Shared\Site.Master:line 24
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Page.Render(HtmlTextWriter writer)
   at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.Mvc.ViewPage.ProcessRequest(HttpContext context)
   at ASP.views_shared_error_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a9d8538d\93f310ba\App_Web_edq0sgjw.0.cs:line 0
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.<>c__DisplayClass4.<Wrap>b__3()
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func)
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
   at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
   at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
   at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)-------------------------------------------------
Any help on this will be of great help.

Thanks.
0
Peter
Telerik team
answered on 17 Feb 2012, 01:52 PM
Hello Huy,

Please, post your question in the MVC forums.

Greetings,
Peter
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Scheduler
Asked by
Camilo Torres
Top achievements
Rank 1
Answers by
Camilo Torres
Top achievements
Rank 1
Huy
Top achievements
Rank 1
Peter
Telerik team
Share this question
or