How to run CLR 2 application as CLR 4 application

怎甘沉沦 提交于 2019-12-09 05:45:07

问题


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!


回答1:


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>



回答2:


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.




回答3:


For folks finding this page via Google in 2013+

Config File Gist
https://gist.github.com/1223509

Blog Post
http://yzorgsoft.blogspot.com/2011/09/greenshot-on-windows-8-net-45.html

<?xml version ="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0.30319" />
    <requiredRuntime version="v4.0.30319" safemode="true"/>
  </startup>
  <runtime>
    <relativeBindForResources enabled="true" />
    <UseSmallInternalThreadStacks enabled="true" />
    <DisableMSIPeek enabled="true"/>
  </runtime>
</configuration>

This config file was pulled from Visual Studio 2012, so it has some extra COM-compatibility and performance tweaks. For environments running hosted code you should probably remove the <runtime> section.



来源:https://stackoverflow.com/questions/896629/how-to-run-clr-2-application-as-clr-4-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!