Tag: DotNet

  • Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

    You might see following error when browse your application site targeting ASP.NET 4.0 on IIS 7 or 7.5 server.

    HTTP Error 500.21 – Internal Server Error
    Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

    Cause & Solution

    If IIS is enabled after DotNet 4 installation then ASP.NET is not registered with IIS. You will see the error if your site is targeting ASP.NET 4. To resolve this issue, run the following from elevated command line to register ASP.NET 4:

    aspnet_regiis.exe –i

    This will register asp.net with IIS. The aspnet_regiis.exe file can be found in either

    • %windir%Microsoft.NETFrameworkv4.0.30319
    • %windir%Microsoft.NETFramework64v4.0.30319 (on a 64-bit machine)

    More info for ASP.NET IIS Registration Tool (Aspnet_regiis.exe) can be found at http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx

  • Configure PowerShell to use DotNet 4.0

    You might get following error when you load a snap-in that is written by DotNet 4.0.

    This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

    This is because by default, PowerShell uses DotNet version 2.0 CLR. To use powershell load DotNet 4.0 assemblies, the following settings need to be added in PowerShell.exe.config under C:WindowsSysWOW64WindowsPowerShellv1.0.

    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">
            <supportedRuntime version="v4.0.30319"/>
            <supportedRuntime version="v2.0.50727"/>
        </startup>
    </configuration>

    Note:

    1. Above applies to 64bit windows server 2008 r2. On a 32 bit machine, PowerShell.exe.config can be found at C:windowsSystem32WindowsPowerShellv1.0
    2. Create PowerShell.exe.config if this file is not found.
  • Mixed mode assembly Error After Upgrading to DotNet 4.0

    After upgrading existing DotNet 2.0 or 3.5 application to DotNet 4.0, you might see following error message

    Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

    To fix this issue, put a config file next to your exe called <exename>.exe.config with the following content:

    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy=”true”>
    <supportedRuntime version=”v4.0″/>
    </startup>
    </configuration>

    Or if your exe already has config file, you can just append <startup> element section. To know more detail, check out Mark Miller’s post What is useLegacyV2RuntimeActivationPolicy for?

    Update – 2011/11/15.

    Just hit a similar issue today when I referrence SMO in a DotNet 4 Executable

    Microsoft.SqlServer.Management.Dac.DacException: Unable to install DacInstance. Please verify the components of the application. —> System.IO.FileLoadException: Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

    The solution is same – in app.config file of the executable, add the following settings:

    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy=”true”>
    <supportedRuntime version=”v4.0″/>
    </startup>
    </configuration>

  • Enable DotNet 3.5 from command line

    To enable DotNet 3.5 from command line, run following from elevated command prompt

    dism.exe /online /enable-feature /featurename:NetFx3

  • Could not load type System.ServiceModel.Activation.HttpModule

    If you install DotNet framework 4.0 on Windows Server 2008 or R2 after enabling IIS,  you might see following error when browse your application site made of ASP.NET 4.0 (or run on ASP.NET 4.0 application pool).

    Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.
    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.TypeLoadException: Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

    Cause & Solution

    If IIS is enabled after DotNet 4 installation then ASP.NET is not registered with IIS. You will see the error if your site is targeting ASP.NET 4. To resolve this issue, run the following from elevated command line to register ASP.NET 4:

    aspnet_regiis.exe /iru

    The aspnet_regiis.exe file can be found in either

    • %windir%Microsoft.NETFrameworkv4.0.30319
    • %windir%Microsoft.NETFramework64v4.0.30319 (on a 64-bit machine)

    More info for ASP.NET IIS Registration Tool (Aspnet_regiis.exe) can be found at http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx