Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I receive the error message "Cannot perform runtime binding on a null reference" on my Profile page,

Line 9:

Line 10: This is My First View

Line 11: My Data is : @ViewBag.CustomerData.CustomerName
Line 12:

Line 13:

Source File: d:\MvcApplication1\MvcApplication1\Views\Test\MyFirstView.cshtml Line: 11



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: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference

Source Error:

[RuntimeBinderException: Cannot perform runtime binding on a null reference]
   CallSite.Target(Closure , CallSite , Object ) +80
   ASP._Page_Views_Test_MyFirstView_cshtml.Execute() in d:\MvcApplication1\MvcApplication1\Views\Test\MyFirstView.cshtml:11
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +196
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +127
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +257
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +294
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +15
   System.Web.Mvc.<>c__DisplayClass1a.<invokeactionresultwithfilters>b__17() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
   System.Web.Mvc.<>c__DisplayClass1c.<invokeactionresultwithfilters>b__19() +25
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +175
   System.Web.Mvc.Async.<>c__DisplayClass2a.<begininvokeaction>b__20() +89
   System.Web.Mvc.Async.<>c__DisplayClass25.<begininvokeaction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +44
   System.Web.Mvc.<>c__DisplayClass1d.<beginexecutecore>b__18(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.<>c__DisplayClass4.<makevoiddelegate>b__3(IAsyncResult ar) +16
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +54
   System.Web.Mvc.Async.<>c__DisplayClass4.<makevoiddelegate>b__3(IAsyncResult ar) +16
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +12
   System.Web.Mvc.<>c__DisplayClass8.<beginprocessrequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<makevoiddelegate>b__3(IAsyncResult ar) +16
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +58
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +11
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9987157
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Can anyone explain to solve it ?




Stack Trace:

What I have tried:

when remove sintax @ViewBag.CustomerData.CustomerName at MyFirstViewcshtml ...It works ...
Posted
Updated 31-Aug-22 1:52am

May be Your CustomerData is null

This is My First View 
@if(ViewBag.CustomerData!=null){
My Data is : ViewBag.CustomerData.CustomerName
}else {
My Data is : null
}



Or

Check value assign in index controller for CustomerData
 
Share this answer
 
Comments
Member 13574900 16-Dec-17 2:30am    
Thank you ...!! It works ....Thank you for opinion
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.
 
Share this answer
 
Comments
Richard MacCutchan 31-Aug-22 8:51am    
The question was solved almost five years ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900