Developer OneNote

Emma's OneNote for Microsoft Windows, Office and Programming

Category: Development

Make IIS 7.5 application pools run as NETWORK SERVICE

25 August, 2010 | Category: Development

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.

Read more »

Mixed mode assembly Error After Upgrading to DotNet 4.0

19 August, 2010 | Category: Development

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, just append following <startup> element to config file.

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup>

If your exe already has config file, just append following <startup> element to config file.

If you really want to knon more detail, check out Mark Miller’s post What is useLegacyV2RuntimeActivationPolicy for?

Windows Phone 7 Application Development Get Start

16 August, 2010 | Category: Development

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.

Read more »

Perl Replace String in File

23 June, 2010 | Category: Development

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

18 June, 2010 | Category: Development

If you install DotNet framework 4.0 on IIS server and then enable DotNet 3.0 or 3.5 WCF features, 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′.

Resolution

To resolve this issue, run the following from command line:

aspnet_regiis.exe /iru

The aspnet_regiis.exe file can be found in either

  • %windir%\Microsoft.NET\Framework\v4.0.30319
  • %windir%\Microsoft.NET\Framework64\v4.0.30319 (on a 64-bit machine)

Microsoft Training Kits

8 June, 2010 | Category: Development

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

Apr 20 – Add Silverlight 4 Training

May 13 – Add Office 2010 and SharePoint 2010 Training Kit

June 9 – Add Windows Azure Platform Training Kit

Aug 16 – Update SQL Server 2008 R2 & Windows Azure Platform Training Kits

Perl Last Element of Split

8 June, 2010 | Category: Development

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

8 June, 2010 | Category: Development

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 .

Read more »

Perl Escape Backslashes in String Substitution

8 June, 2010 | Category: Development

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 .

Read more »

Perl Add Directory to Path

8 June, 2010 | Category: Development

Say you have a directory d:\bin and you want to add it to path environment at the beginning of your Perl script. Following code will do the trick.

my $dir="d:\\bin";
$ENV{PATH}.=";$dir";

Then $dir will be included in new $ENV{PATH}