Category: Development

  • Make IIS 7.5 application pools run as NETWORK SERVICE

    There is a break change in IIS 7.5 on Windows 7 and Windows Server 2008 R2. The default identity for running an application pool is "ApplicationPoolIdentity".  If you have a web application developed against application pools running with NETWORK SERVICE on IIS6/7, it might break after migrated to IIS 7.5 due to default application pool identity change.

    (more…)

  • 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>

  • Windows Phone 7 Application Development Get Start

    Getting Start with Windows Phone 7 Application Development

    1. Download the tools and emulator from http://developer.windowsphone.com
    2. Using the tutorial from the Microsoft Channel9 Learning Center, build your first application.

    (more…)

  • Install PowerShell From Command Line

    To install PowerShell on Windows Server 2008 R2 or Hyper-V Server 2008 R2, following features needs to be installed.

    1. NetFx2-ServerCore
    2. NetFx3-ServerCore
    3. MicrosoftWindowsPowerShell

    Because Powershell is built on DotNet framework, DotNet 2.0 and 3.5  has to be installed prior to PowerShell installation.

    To install PowerShell from command line, run following from elevated command prompt

    DISM.exe /online /enable-feature /featurename:NetFx2-ServerCore DISM.exe /online /enable-feature /featurename:NetFx3-ServerCore DISM.exe /online /enable-feature /featurename:MicrosoftWindowsPowerShell

    Or run following command if it’s an 64bit machine

    DISM.exe /online /enable-feature /featurename:NetFx2-ServerCore-WOW64 
    DISM.exe /online /enable-feature /featurename:NetFx3-ServerCore-WOW64 
    DISM.exe /online /enable-feature /featurename:MicrosoftWindowsPowerShell-WOW64 

  • 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

  • Perl Replace String in File

    This code snippet demonstrates how to replace string in file using perl. This perl script takes in an input file, replaces the all string foo with bar.

    my $file = $ARGV[0];
    my $filetmp = "$ARGV[0].tmp";
    open (INPUT, "< $file") or die("Unable to open $file");
    open (TMP, "> $filetmp") or die("Unable to open $filetmp");
    while(<INPUT>) {
        if(/foo/) {
            s/foo/bar/;   # replace foo with bar   
        }
        print TMP $_;
    }
    close(INPUT);
    close(TMP);
    rename $filetmp, $file;

  • 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

  • Microsoft Training Kits

    The Microsoft Training Kit is free download that contains useful training resources. Here is a list of some latest useful training kits, the training content includes demo, videos, presentations, hands on lab and some code samples. Enjoy it

    Update History

    • 2010 Apr – Add Silverlight 4 Training
    • 2010 May – Add Office 2010 and SharePoint 2010 Training Kit
    • 2010 June – Add Windows Azure Training Kit
    • 2010 Aug – Update SQL Server 2008 R2 & Windows Azure Training Kit
    • 2010 Sep – Add Windows Phone 7 Training Kit
    • 2010 Dec – Add VS LightSwitch & Lync Server 2010 Training Kit
    • 2011 March – Add PHP on Windows SQL Server Training Kit
    • 2012 March – Add SQL Server 2012 Developer Training Kit
    • 2012 April – Add Windows Server 8 HOL
    • 2012 June – Add Azure Training Kit
    • 2012 Dec – Add Windows Phone 8 Training Kit
  • Perl Last Element of Split

    There is an easier way to get last element on a split operation, save split result to an array and use $array[-1] and this will access last element of the arrays.

    Example

    $strings=”foo,bar,test”;
    my @fields = split(/,/, $strings);
    print $fields[-1] ;  # the last str in $strings

  • Perl Backslash in Regular Expression

    This note is for a trick to use Q and E  to escape characters for regular expression. You will find it very useful when you do string substitution and your pattern contains characters like slashes or backslashes .

    (more…)