Hi,
I'm almost done with the bottom level layers, but not with the MVC3 using Razor syntax.
I was always getting NullReferenceException running the project. I found that the Model is have null value while opening the view. I don't know where I've went wrong. Any help would be appreciated.
Thanks & Regards,
SreeRam.
Hi Rocky,
I found that there is an error in the configuration. Let me explain the situation
I've five projects that are in a single solution.
1. Dal
2. DalMock
3. DalEF
4. Library
5. WebUI(Mvc3)
I'm developing the project for a 2-tier web deployment with custom authentication. So I placed the below line in the Web.Config file under the app settings in the WebUI project
<add key="CslaAuthentication" value="Csla"/>
Since I'm developing in a 2-tier environment, I've also placed the DalManagerTypes in the same web.config file under app settings.
<add key="DalManagerType" value="LX.DalMock.DalManager,LX.DalMock"/>
<!--<add key="DalManagerType" value="LX.DalEf.DalManager,LX.DalEf"/>-->
Since I'm using two databases for my application, one for authentication and one for business data, I placed the database connection strings like below
<connectionStrings>
<add name="LXEntities" connectionString="metadata=res://*/LXDB.csdl|res://*/LXDB.ssdl|res://*/LXDB.msl;provider=System.Data.SqlClient;provider connection string="data source=TCS-TFSDB;initial catalog=LXDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="LXSecurityDBEntities" connectionString="metadata=res://*/LXApplicationServies.csdl|res://*/LXApplicationServies.ssdl|res://*/LXApplicationServies.msl;provider=System.Data.SqlClient;provider connection string="data source=TCS-TFSDB;initial catalog=LXSecurityDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
That's it with the web.config file.
Below is the error I'm getting while running the project.
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.ArgumentException: Type LX.DalMock.DalManager,LX.DalMock could not be found
Source Error:
Line 18: throw new NullReferenceException("DalManagerType");
Line 19: if (_dalType == null)
Line 20: throw new ArgumentException(string.Format("Type {0} could not be found", dalTypeName));
Line 21: }
Line 22: return (IDalManager)Activator.CreateInstance(_dalType);
Source File: D:\Projects\LX\ProjectSource\LX\LX.Dal\DalFactory.cs Line: 20
Stack Trace:
[ArgumentException: Type LX.DalMock.DalManager,LX.DalMock could not be found]
LX.Dal.DalFactory.GetManager() in D:\Projects\LXI\ProjectSource\LX\LX.Dal\DalFactory.cs:20
LX.Library.AccountTypes.DataPortal_Fetch() in D:\Projects\LXI\ProjectSource\LX\LXLibrary\NameValueLists\AccountTypes.cs:108
lambda_method(Closure , Object , Object[] ) +62
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) +392
[CallMethodException: DataPortal_Fetch method call failed]
Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) +475
Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) +44
Csla.Reflection.LateBoundObject.CallMethod(String method) +31
Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) +322
[DataPortalException: DataPortal.Fetch failed (Type LX.DalMock.DalManager,LX.DalMock could not be found)]
Csla.DataPortal.Fetch(Type objectType, Object criteria) +643
Csla.DataPortal.Fetch() +62
LX.Library.AccountTypes.GetList() in D:\Projects\LXI\ProjectSource\LX\LXLibrary\NameValueLists\AccountTypes.cs:81
LX.WebUI.Models.HomeModel.get_ATypes() in D:\Projects\LXI\ProjectSource\LX\LX.WebUI\Models\HomeModels.cs:14
ASP._Page_Views_Home_Index_cshtml.<Execute>b__4() in d:\Projects\LXI\ProjectSource\LX\LX.WebUI\Views\Home\Index.cshtml:17
System.Web.WebPages.<>c__DisplayClassb.<RenderSection>b__9(TextWriter tw) +283
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +12
System.Web.WebPages.WebPageBase.Write(HelperResult result) +67
ASP._Page_Views_Shared__LayoutCustom_cshtml.Execute() in d:\Projects\LXI\ProjectSource\LX\LX.WebUI\Views\Shared\_LayoutCustom.cshtml:101
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +88
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +102
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +12
System.Web.WebPages.WebPageBase.Write(HelperResult result) +67
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +66
System.Web.WebPages.WebPageBase.PopContext() +262
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +220
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
The configuration all seems fine. Based on your exception, it sounds like your DAL assemblies are not in the web site's bin folder.
If you are going to deploy in a 2-tier environment, then the DAL assemblies need to be installed on the web server.
Thanks Rocky,
The bin folder contains the dal assemblies. My bin folder is having LX.Dal.dll but not the Mock db dll. I have added reference of Mock Db project to WebUI Project. Because we are using the 2-tier architecture I don't think that this violates the n-tier
architecture goals.
Suggest me if I'm not correct.
As long as you're not using the Mock Db assembly from within your WebUI project. That is, the reference is there ONLY to make sure the mock assembly is copied to your bin folder automatically. I've done this as otherwise you need post build events or to manually copy the dal assemblies to your bin, but you do need to make sure no one actually uses any types from the WebUI.
Copyright (c) Marimer LLC