Bruno Lopes
Bruno Lopes

Reputation: 3056

Assembly redirection in code instead of app.config

I'm using ironruby to execute a script that loads an assembly with a dependency that needs to be redirected from v2.0.0.0 to v3.5.0.0 in the app.config like this:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.CompactFramework.Build.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="9.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Engine" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
</runtime> 

The script works with this redirection, but this requires me to always change the ironruby app.config, and it applies to all scripts. I need to either:

How?

Upvotes: 0

Views: 845

Answers (2)

M. Scott Ford
M. Scott Ford

Reputation: 2989

You can avoid changing the IronRuby app.config by using a hack that I wrote called configuration_settings_hackery.rb. You can read about it on my blog. The blog post contains a link to a gist on github.

I use this hack every day, and I have been having a lot of success with it. You will need to change the last line of the configuration_settings_hackery.rb file to point to the location of your app.config. The version that I posted just looks for c:\app.config.

Upvotes: 1

Lukas Cenovsky
Lukas Cenovsky

Reputation: 5660

I would try creating a new AppDomain with AppDomainSetup.ConfigurationFile set to your special app.config and then run your script in that AppDomain.

Upvotes: 0

Related Questions