简体   繁体   中英

'useLegacyV2RuntimeActivationPolicy' does not work if config file is not in installation folder

After converting the .net application to 4.0v I encountered problems related to interop assembly, as a work around to the problem the following was embedded in the configuration file

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

However the above solution fails when the config file is not in the installation folder, I would like to know whether it is possible to force the application to read the above setting from a config file that is located in a different folder (other than installation folder) or is it possible to programmatically achieve what 'useLegacyV2RuntimeActivationPolicy' tag does?

I found this article that will solve the problem.

http://reedcopsey.com/2011/09/15/setting-uselegacyv2runtimeactivationpolicy-at-runtime/

Just add the static class in his write up into the assembly that has the Com Interop method and all will be well. The static constructor executes when the assembly is loaded and sets the useLegacyV2RuntimeActivationPolicy for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM