Search code examples
c#.net-4.0.net-2.0versionsmo

"useLegacyV2RuntimeActivationPolicy=true" not working when application is loaded using Process.Start


I have an application that uses the SQL Management Objects (Microsoft.SqlServer.Smo.dll) and in order to make it work in .NET 4, I need to insert this block in the app.config file:

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

It works, but if I execute this application from another application, using

System.Diagnostics.Process.Start("myApplicationThatUsesSmo.exe")

It does not work. The LegacyV2Runtime is not activated.

I used this implementation:

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

to check if the LegacyV2Runtime is loaded, and it is not. If I run the application directly, or from within VS2010, the test passes and the Smo works.

Anyone knows what am I missing?


Solution

  • Nevermind. The file "myApplicationThatUsesSmo.exe.config" was indeed missing in the folder where "myApplicationThatUsesSmo.exe" was being started.

    "myApplicationThatUsesSmo.exe" is set as a reference for "myApplicationThatCallsProcessStart.exe" and so it is copied to the "myApplicationThatCallsProcessStart.exe" output folder. But its config file is not. There was a build event coping this file, but some how it was erased and than things stoped working.

    I will let this answer here, in case someone else face the same situation.