Trying to update MVC 4 to MVC 5 and got exception - asp.net-mvc-4

After migration from MVC 4 to MVC 5 got an exception:
Could not load type 'System.Web.Mvc.ViewMasterPage<PropertyViewModel>'. Could not load type 'System.Web.Mvc.ViewMasterPage<PropertyViewModel>'. Could not load type 'System.Web.Mvc.ViewMasterPage<PropertyViewModel>'.
It occurs on #Html.DIsplayFor(x=>x.MyModel.Title) where title is empty String.
Before the update everything was working.
Updated:
who has experience in MVC, please help. After update web.config with these:
<pages
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
i`ve got - Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'. How i can fix it?

Make sure you include your namespace for that ViewModel.
Here's an example:
#model MiniRegistration.Web.Areas.Home.ViewModels.RegistrationViewModel
Also check that the web.config file located in your View Directory, has the following page directives:
<pages
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
This website breaks it down nicely:
http://www.codewrecks.com/blog/index.php/2009/04/05/could-not-load-type-systemwebmvcviewpage/
And this post reflects a similar problem to yours with a solution as well:
ASP.NET MVC Strongly Typed Partial View, gives could not load type error

Related

Http PUT request to a 3rd party API gives Stream is already consumed error

My code is making a simple PUT http request to 3rd party API.
But there an intermittent issue I am facing
Error says - The stream was already consumed. It cannot be read again.
Following is the stack trace -
Anyone knows what could be the problem..
[{"level":0,"method":"System.Net.Http.StreamContent.PrepareContent","assembly":"System.Net.Http, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","line":0},{"level":1,"method":"System.Net.Http.StreamContent.SerializeToStreamAsync","assembly":"System.Net.Http, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","line":0},{"level":2,"method":"System.Net.Http.HttpContent.CopyToAsync","assembly":"System.Net.Http, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","line":0},{"level":3,"method":"System.Net.Http.HttpConnection+<SendRequestContentAsync>d__58.MoveNext","assembly":"System.Net.Http, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","line":0},{"level":4,"method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","line":0},{"level":5,"method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","line":0},{"level":6,"method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","line":0},{"level":7,"method":"System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult","assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","line":0},{"level":8,"method":"System.Net.Http.HttpConnection+<SendAsyncCore>d__53.MoveNext","assembly":"System.Net.Http, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","line":0}]

Trace Error in ASP.NET MVC Application

I am creating my first MVC application with VS 2012 on WIN 10. I added this line in System.Web section of Web.config file:
<trace enabled="true" pageOutput="True" />
My machine.config file has this line:
<section name="trace" type="System.Web.Configuration.TraceSection, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
and this line:
<section name="deployment" type="System.Web.Configuration.DeploymentSection, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowDefinition="MachineOnly"/>
When I run my application and enter this URL:http://localhost/MvcDemo/Trace.axd, I get the following error:
How can I solve it?
Acccording to this blog post: http://knucklebones.blogspot.com/2010/11/enable-tracing-in-aspnet-mvc.html
You need to add a little extra web.config plumbing for MVC:
<system.diagnostics>
<trace>
<listeners>
<add name="WebPageTraceListener"
type="System.Web.WebPageTraceListener, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</listeners>
</trace>
</system.diagnostics>

MSChart not working in other machines

I've installed and configured MSChart on my dev server and everything working fine when I access charts from my machine but same don't work when it's accessed from different machines. It throws following error,
No http handler was found for request type 'GET'
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.Web.HttpException: No http handler was found for request type 'GET'
I've already updated config file of server's web app with following,
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\Temp\;" />
</appSettings>>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>
<handlers>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>

Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling

I get this below error when i add Enterprise library 5.0 file MS.Practices.EnterpriseLibrary.ExceptionHandling.dll for my wcf application.
An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
<exceptionHandling>
<exceptionPolicies>
<add name="Global Policy">
<exceptionTypes>
<add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None">
<exceptionHandlers>
<add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Global Message." wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" />
<add name="Custom Handler" type="AppMessageExceptionHandler, ExceptionLibraryForWCF"/>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
<add name="Handle and Resume Policy">
<exceptionTypes>
<add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="None">
<exceptionHandlers/>
</add>
</exceptionTypes>
</add>
<add name="Propagate Policy">
<exceptionTypes>
<add name="Exception" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
<exceptionHandlers/>
</add>
</exceptionTypes>
</add>
<add name="Replace Policy">
<exceptionTypes>
<add name="SecurityException" type="System.Security.SecurityException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add name="Replace Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ReplaceHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" exceptionMessage="Replaced Exception: User is not authorized to peform the requested action." replaceExceptionType="System.ApplicationException, mscorlib"/>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
<add name="Wrap Policy">
<exceptionTypes>
<add name="DBConcurrencyException" type="System.Data.DBConcurrencyException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException">
<exceptionHandlers>
<!--<add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" exceptionMessage="Wrapped Exception: A recoverable error occurred while attempting to access the database." wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" /> -->
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
Below is my web.config declaration for my exception handling
-->
Your web.config isn't actually in the post.
In any event, you've got a reference to Entlib 2.0 in your config file. You need to update to point at the Entlib 5 version number and public key token. It's probably in your element, but if it's there I wouldn't be surprised if the rest of your file also had the wrong version #'s.
[update on further reflection]
Actually, based on the error message, there's another possibility - the runtime is finding the 2.0 assembly instead of the 5.0 assembly when it goes to load. Double check all your assembly references, and check your bin directory - make sure it's got the right assembly in it.
You can also try running the fuslogvw tool on the web server - it'll tell you what assemblies the runtime tried to load, and where it looked for them.
I had a similar problem caused by source control. I checked in an old copy of a project file after a coworker updated a project. I simply found the project that was referencing the assembly/ project reference in error, removed the reference, re-added the reference and rebuilt the solution. bingo.

WCF: Adding BehaviorExtensions generates a security exception

When adding a <behaviorExtensions> section to the web.config file of my project I get a security exception (see below). What can be the problem? I follow this solution to another issue: link
Adding this:
<extensions>
<behaviorExtensions>
<add name="customWebHttp" type="CloudService4_WebRole.CustomHttpBehaviorExtensionElement, CloudService4_WebRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
results in:
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.