While I was working on some code today and found that some NuGet packages where out of date. So I went to update tab in Manage NuGet packages window and updated all of them. MySql.Data package (not important which package, just an example) was also updated in that from version 6.7.8 to current / latest (6.9.6). I tried to run the application to test the updates made in referring packages. I encountered following error: TypeInitializationException was unhandled An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module. Additional information: The type initializer for '[Application Name]' threw an exception. Looking at this exception, it doesn't seems to be obvious what is going wrong here. There isn't even option for "View details". Many of you may get stuck on this and spent hours before you figure out that the AssemblyBinding.dependentAssembly.bindingRedirect are creating this » Read more

 Jsinh        

Did you encountered following exception / error when trying to run ASP.NET MVC web application? The view must derive from WebViewPage, or WebViewPage or Type 'ASP.PageViews_ViewStartcshtml' does not inherit from 'System.Web.WebPages.StartPage'. I encountered while I was playing with MVC 5 (applies to MVC 3 and 4 also) application. Every razor page should inherit from System.Web.Mvc.WebViewPage. You can resolve this issue by adding following line at the top in each view razor (*.cshtml) page: @inherits System.Web.Mvc.WebViewPage and add following line at the top of _ViewStart.cshtml : @inherits System.Web.Mvc.ViewStartPage or you can add a web.config file and add following (in root of Views folder where the Razor pages reside) <?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web. » Read more

 Jsinh        

Another application configuration setting you will observe in web.config of your ASP.NET MVC application is webpages:Version <add key="webpages:Version" value="3.0.0.0" /> The value for this setting currently is showing 3.0.0.0. This indicates the version of Webpages - Razor view engine is to be used. This application setting was introduced during update release of ASP.NET MVC 3 and is used to identify which Razor view engine to be used for handling webpages in your MVC application. Based on my digging into ASP.NET WebStack codebase on codeplex, Build and Revision component of version number are optional or can differ. If these two components of version number are not present or not found to be valid System.Web.WebPages.Deployment library fixes it to x.x.0.0 and returns the version number. What will happen if webpages:Version » Read more

 Jsinh        

If you open your web.config at root of your MVC project you will find bunch of default appsetting keys added by MVC or WebAPI. One of the appsetting with key webpapges:Enabled is added which as default value as false. So what is the deal with this appsetting? To find out the answer to this simple question I started searching ASP.NET WebStack codebase on codeplex. This appsetting is processed by the System.Web.WebPages.Deployment - WebPagesDeployment.cs code. Dry-running the code base I got answer to my query. Three possibility for the appsetting - webpages:Enabled: Key - value not added at all or not having a valid boolean value. Key - value added and set to false. Key - value added and set to true. Case 1: In this case when PreApplicationStartCode > Start method is called which in turn calls > StartCore which internaly checks this application » Read more

 Jsinh        

When creating a MVC project using Visual Studio you will observe that creation process will add two web.config files to your project. In root of the project folder. In the root of the Views folder in the project folder. Question: The web.config in the root of the project is natural and expected, but why MVC project contains a web.config files in the views folder? Answer: To quote wikipedia: A controller can send commands to the model to update the model's state (e.g., editing a document). It can also send commands to its associated view to change the view's presentation of the model (e.g., by scrolling through a document). In ASP.NET MVC concept of routing is used that helps decoupling URLs mapping with specific files. Due to the routing definitions and route collection definitions of any application enables the application to serve a URL to » Read more

 Jsinh        

In programming world everything is not a piece of cake. At times you need to do things more than available out-of-the-box. One of the common thing you seems to do is to modify or access your application’s configuration. There are two type of configuration files: App.Config (Used by Windows Project type application) Web.Config (Used by Web Project type application) We do lots of dirty stuffs to get the path and name of the file that is main configuration for the windows or web application. The simplest way to access the configuration file associated with the currently running application is using: System.AppDomain.CurrentDomain.SetupInformation.ConfigurationFile Verified against: Windows Forms, Console Application, WPF Application, ASP.NET MVC 3 application. » Read more

 Jsinh