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 resolution is same – in app.config file of the executable, add the following settings:

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

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

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 Platform Training Kit
  • 2010 Aug – Update SQL Server 2008 R2 & Windows Azure Platform 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

Visual Studio Themes and Color Schemes

I just came cross this site http://studiostyles.info/ which provides Visual Studio color schemes for free download. All color schemas work for both Visual Studio 2008 and 2010. Every schema has screenshots so you can see how it looks like before downloading it.

You can follow following steps to import the color schema into Visual Studio.

  1. In Visual Studio, choose Tools > Import and Export Settings
  2. Choose Import Selected Environment Settings and select whether you want to back up your existing settings or not
  3. Click Browse to choose the file you downloaded.
  4. You get a choice which settings you want to import – choose all of them since the file only contains color settings and won’t touch your other VS settings.
  5. Click Finish and you’ll see the new colors.

Note: if you save the file to My Documents > Visual Studio 2010 > Settings, you’ll have quick access to choose the settings file in step 3 above.

Continue reading