Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run CLR 2 application as CLR 4 application

Tags:

.net

clr

Lets say I have an old application which will try to load an external assembly.

  • The old application is compiled to CLR 2.
  • The new assembly is compiled to CLR 4.

I would like to be able to run that old application inside CLR 4. I remember there was some xml manifest magic involved.

How can I create that manifest xml file to tell that oldapplication.exe shall run under CLR 4?

I found some suggestions, but they do not seem to work for me.

  • http://www.mibuso.com/forum/viewtopic.php?f=23&t=33840&view=next
  • http://geekswithblogs.net/technetbytes/archive/2007/06/01/112928.aspx
  • http://msdn.microsoft.com/en-us/library/a5dzwzc9.aspx

oldapplication.exe.config:

<?xml version ="1.0"?>
<configuration>
 <startup>
      <!--set the appropriate .net version-->
      <requiredRuntime version="4.0.0.0"/>
 </startup>
</configuration>

While giving another shot i found this file to serve as my template:

C:\Windows\Microsoft.NET\Framework\v4.0.20506\Aspnet_regsql.exe.config

<?xml version ="1.0"?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0.20506"/>
        <requiredRuntime version="v4.0.20506" safemode="true"/>
    </startup>
</configuration>

I also updated the code to report current CLR:

Console.WriteLine(typeof(object).Assembly.ImageRuntimeVersion);

It works now!

like image 366
zproxy Avatar asked May 22 '09 06:05

zproxy


People also ask

What is .NET CLR version?

The Common Language Runtime (CLR), the virtual machine component of Microsoft . NET Framework, manages the execution of . NET programs. Just-in-time compilation converts the managed code (compiled intermediate language code) into machine instructions which are then executed on the CPU of the computer.

How CLR works in. net Framework?

CLR provides the services and runtime environment to the MSIL code. Internally CLR includes the JIT(Just-In-Time) compiler which converts the MSIL code to machine code which further executed by CPU. CLR also uses the . NET Framework class libraries.


2 Answers

You need to give the proper version number. Note that this is the beta 1 version, it will change until RTM settles one:

<configuration>
 <startup>
      <supportRuntime version="4.0.20506"/>
 </startup>
</configuration>
like image 104
Jb Evain Avatar answered Sep 27 '22 21:09

Jb Evain


I believe you want to use supportedRuntime, not requiredRuntime.

"The <supportedRuntime> element should be used by all applications built using version 1.1 or later of the runtime." (http://msdn.microsoft.com/en-us/library/a5dzwzc9.aspx). Mke sure the version string exactly matches "the installation folder name" for the version you want.

like image 26
Matthew Flaschen Avatar answered Sep 27 '22 21:09

Matthew Flaschen