3
votes

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?

1
I notice that it looks like you're getting the exception from an automated test script. Which test runner are you using? Does it pick up on the .config file? (This only happens automatically for .exe files.)Mark Seemann
@MarkSeemann Thanks for your comment, you made me read the error message and I noticed that the error was pointing to the F# core from the automated test launcher, and not my other project which I thought was having a problem. It seems that that automated test script (which calls the other project I am getting that error in) uses F# core 4.3 and not 4.3.1 like I had thought, which might be causing problems.Choub890

1 Answers

0
votes

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.