Internal Server Error Asp.Net MVC and WebApi migration

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Few years age we implemented an ASP.NET  MVC 2.0 application. Now we waned extend the application for new REST services which can be consumed by mobile applications. For this reason we use NuGet update MVC on version 4 and to install the newest WebApi. After installation many new assemblies have been installed and old have been replaced.
After some tweaks application could have been started. One of issues we had was re-implementing of classes which has derived from ControllerBase. Suddenly all our controllers derived from our implementation of controller base like:

MyControllerBase : ControllerBase.

Because this does not work well in new MVC, we decided to implement controller base functionality as ActionFilter. By trying to ignore lost time this might be declared as successful action.

Unfortunately after deployment of application to production system any call to some WebApi action ended in “500 Internal Server Error”.
The stupid on this error is that it is responded on almost any error which can happen in the WebApi stack. For example, I have expected that there is some bug in some of our component like Action Handlers etc. After disabling all of them I was sure that the error is coming from WebApi stack itself. Unfortunately there is no easy way to dig behind the hub and grab out the error stack trace. I tried to implement DelegatingHandler etc. Nothing helped. In that handler implementation I was only able to approve the error code which I already know.

At the end I have taken the configuration of the similar application which is already running in production and compared Web.Configs. The only problem here was that the good application has very different configuration for design reasons. So compare was not easy. Finally I found  following in the config:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

     

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />

       <assemblyIdentity name="Microsoft.Visual.Enterprise.ASPNetHelper"
                         
publicKeyToken="b03f5f7f11d50a3a" culture="neutral"
/>

        <codeBase version="8.0.0" href="file://c:/Program Files/Microsoft Visual Studio 8/common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Enterprise.ASPNetHelper.dll" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Configuration"
                        
 publicKeyToken="b03f5f7f11d50a3a" culture="neutral"
/>

        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />

      </dependentAssembly>

      

    </assemblyBinding>

 

The web.config has to be fixed manually as follows (NuGet will not do it for you):

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

     

     <dependentAssembly>

        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />

      </dependentAssembly>

     

    . . . System.Configuration remains as it is . . .

     

    </assemblyBinding>

 

Enjoy advantages of open source Smile


Posted Jul 24 2012, 12:00 PM by Damir Dobric
Filed under: , ,
developers.de is a .Net Community Blog powered by daenet GmbH.