Category: Development

  • 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 WordPress to Use Proxy

    If you setup a WordPress site on a server in intranet behind a proxy, you might get following error when you search plugins and themes in admin console.

    An Unexpected HTTP Error occured during the API request.

    This is because WordPress does not know the proxy server to talk to external internet. To resolve this, simply enable proxy by adding following lines to wp-config.php file

    define(‘WP_PROXY_HOST’, ‘192.168.110.1’);
    define(‘WP_PROXY_PORT’, ’80’);

    Replace 192.168.110.1 and 80 with your actual proxy server and port.

    If the intranet proxy requires user authentication, appending following lines.

    define(‘WP_PROXY_USERNAME’, ‘UserName_ReplaceMe’);
    define(‘WP_PROXY_PASSWORD’, ‘UserPassword_ReplaceMe’);

  • Common TFS commands

    tf.exe is Team Foundation source control command-line tool which can be used to perform source control operations without GUI interaction. Here are some common tf commands I use in my daily work. You can run command tf /? to view more or visit MSDN TF Command Line Tool Reference

    Common tf commands

    sync Sync files under current folder tf get
    Sync files under current folder and all sub folders tf get . /r
    Sync file to a given revision tf get <filename>;<revision>
    Display what would be synced tf get /preview
    Force sync tf get /all
    Force sync, will override existing files tf get /force
    add Add new file tf add <filename>
    checkout Checkout file for editing tf checkout <filename>
    delete Delete file tf delete <filename>
    rename Rename file tf rename
    checkin Submit open files to tfs server tf checkin
    resolve Resolve file conflicts tf resolve
    Resolve file with automatical merge tf resolve /i /auto:acceptmerge>
    shelve Package pending change and store to tfs server tf shelve <shelvesetname>
    unshelve Unpackage shelve from tfs server into current workspace tf unshelve <shelvesetname>
    workspace Update workspace configurations tf workspace <workspacename>

    Common tfpt commands

    tftp.exe is a command line tool that you can use to work with files and directories under version control, team projects, and work items. Some commands display a graphical user interface when run. tfpt.exe is part of Team Foundation Server Power Tools which can be downloaded here.

    Revert unchanged files tfpt uu /noget
    Search all modified files not in source control and add to pending change list tfpt online
    Scorch – Remove all files in local workspaces but not in source control tfpt treeclean -delete
    Undo submitted change tfpt undo
    View difference of a shelve tfpt review /shelveset
  • How to debug msbuild issues

    To debug msbuild build failures, you can run following from VS command prompt to get more build log output

    msbuild /v:diag <solutionname>

    If you want to log messages for debug during build, you can use Message tasks. For example, use Message task inside a target

    <Target Name="DisplayMessages">
      <Message Text="Project File Name = $(MSBuildProjectFile)" />
      <Message Text="Project Extension = $(MSBuildProjectExtension)" />
    </Target>

    If you are doing build in VS2010 IDE, you can follow these steps to turn on verbose building to help debug msbuild issues.

    1. Open Visual Studio and go into the Tools->Options menu
    2. Go to Projects and Solutions->Build and Run and set MSBuild project build output verbosity to Diagnostic.
    3. Rebuild your project and now the output will show you all the environment variables and parameters.
  • SQL Server Version History

    By default you can’t restore a sql backup that was taken from a higher version sql server. Otherwise you might get following error when doing restore.

    System.Data.SqlClient.SqlError: The database was backed up on a server running version 10.50.1600. That version is incompatible with this server, which is running version 10.00.2714. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server

    SQL Server version can be checked by running following sql query

    SELECT @@Version

    SQL Server Version History Tracking Table

    Version SQL Server Release
    12.00.2000.8 SQL Server 2014 RTM
    11.00.3000 SQL Server 2012 SP1
    11.00.2100.6 SQL Server 2012 RTM
    10.50.4000 SQL Server 2008 R2 SP2
    10.50.2500 SQL Server 2008 R2 SP1
    10.5.1660.1 SQL Server 2008 R2 RTM
    10.00.5500 SQL Server 2008 SP3
    10.00.4000 SQL Server 2008 SP2
    10.00.2531 SQL Server 2008 SP1
    10.00.1600.22 SQL Server 2008 RTM
    9.00.5000 SQL Server 2005 SP4
    9.00.4035 SQL Server 2005 SP3
    9.00.3042 SQL Server 2005 SP2
    9.00.2047 SQL Server 2005 SP1
    9.00.1399.06 SQL Server 2005 RTM
    8.00.2039 SQL Server 2000 SP4
    8.00.0760 SQL Server 2000 SP3
    8.00.0534 SQL Server 2000 SP2
    8.00.0384 SQL Server 2000 SP1
    8.00.0194 SQL Server 2000 RTM
  • 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.
  • How to run ps1 scripts

    PowerShell scripts are text files with ".ps1" extensions that contain PowerShell commands. Starting with Windows Server 2008, PowerShell is built into the OS. For earlier OS versions, you will need to download PowerShell at Microsoft PowerShell Site and install it.

    To run ps1 scripts, you first need to enable scripts by running:

    Set-ExecutionPolicy RemoteSigned

    Otherwise, you will get this error message:

    File <script> cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

    The most common way to run PowerShell scripts is from Windows PowerShell command prompt. You must specify a path to the script to run it. If the script is in your current folder, then you can run it with:

    .script.ps1

    If the script is in another folder, you need specify the full path:

    c:scriptsscript.ps1

      (more…)

    1. Free ebook: Programming Windows Phone 7

      Microsoft are now giving away the eBook Programming Windows Phone 7 by Charles Petzold.  For detail information of this ebook, view http://blogs.msdn.com/b/microsoft_press/archive/2010/10/28/free-ebook-programming-windows-phone-7-by-charles-petzold.aspx

      You can download a PDF here (38.6 MB).

      And you can download the ebook’s sample code here (5.03 MB).

      untitled

    2. [ODBC Driver Manager] Data source name not found and no default driver specified

      If you run osql.exe utility on server that does not have SQL server installed, you might get following error: [ODBC Driver Manager] Data source name not found and no default driver specified.

      This is because osql utility uses ODBC API to communicate to SQL server and SQL ODBC driver is not installed. To fix this, simple download and install SQL Native Client. For example, if you are using the osql.exe from the SQL 2008 (10.0), you should install the SQL Native Client 10.0 from: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C

    3. Grant Permission to DefaultAppPool Identity

      After upgrading web applications to IIS 7.5 on Windows Server 2008 R2, you might get following error.

      Access to the path ‘d:sitecache.txt’ is denied.
      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.UnauthorizedAccessException: Access to the path ‘d:sitecache.txt’ is denied.
      ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate=”true”/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
      To grant ASP.NET access to a file, right-click the file in Explorer, choose “Properties” and select the Security tab. Click “Add” to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

      (more…)