Search code examples
.netf#dependenciesf#-dataassembly-binding-redirect

F# Binding Redirect not working for F# 4.3.0-4.3.1


I have a F# project in VS 2012 with F# core 4.3.0 and .net 4.5.0 that has a dependency on FSharp.Data via a nugget package. Recently, we have branched a new version of our software and we changed our .net target and F# core version on that branch so the project is now targeting F# core 4.3.1 and .net 4.5.1.

Unfortunately, during runtime I get the following error:

{"[A]Microsoft.FSharp.Core.FSharpOption`1[FSharp.Data.Runtime.BaseTypes.XmlElement] cannot be cast to [B]Microsoft.FSharp.Core.FSharpOption`1[FSharp.Data.Runtime.BaseTypes.XmlElement]. Type A originates from 'FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\FSharp.Core\v4.0_4.3.0.0__b03f5f7f11d50a3a\FSharp.Core.dll'. Type B originates from 'FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Script\AutomatedTestLauncher5.4\FSharp.Core.dll'."}

Following the following stackoverflow question's answer, I have tried creating the following binding redirect in my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Unfortunately, I am getting the same error again. Is there a way to solve this problem, or will I have to find another framework to do what I want other than FSharp.Data?


Solution

  • The project that was giving me problems was being called by another project, and I hadn't change the binding redirect of that project. I did, and it fixed the problem.