views:

83

answers:

2

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:

  • define this redirection either for a single script
  • execute code that registers the redirection before requiring the problematic assembly

How?

A: 

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

Lukas Cenovsky
+1  A: 

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.

M. Scott Ford
Oh, this looks "nice". I'll try it during the weekend :)
Bruno Lopes
Okay, on further investigation I'm not sure this will work. While this works for configuration values, it doesn't for assembly binding. I think I may need to hook into the events .net fires for assembly resolving.
Bruno Lopes