开发者

Can I set the app.config 'useLegacyV2RuntimeActivationPolicy' attribute programmatically?

开发者 https://www.devze.com 2023-01-01 21:13 出处:网络
I had to migrate a .NET 3.5 to 4.0 but some dll\'s were not loading, after googling I found that creating an app.config would solve it:

I had to migrate a .NET 3.5 to 4.0 but some dll's were not loading, after googling I found that creating an app.config would solve it:

<?xml versio开发者_运维技巧n="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
</configuration>

I would like to setup these options without using configuration files, is it possible?


It is possible to set this at runtime, from within a .NET application or library, with some limitations. You can use the ICLRRuntimeInfo interface to handle this. For details, see this article.


It is technically possible. You'd have to host the CLR yourself so you can call the ICLRRuntimeInfo::BindAsLegacyV2Runtime() method before you create the primary AppDomain. A .config file would normally be a much lower pain point unless you are already hosting.

0

精彩评论

暂无评论...
验证码 换一张
取 消