I've refactored some of my code to use (relatively newly introduced) F# Result type that is defined in FSharp.Core like this:
type Result<'TOk,'TError> =
| Ok of 'TOk
| Error of 'TError
Everything compiles but at runtime the application fails with the following exception:
Could not load type 'Microsoft.FSharp.Core.FSharpResult`2' from assembly 'SomeAssembly, Version=1.25.24.0, Culture=neutral, PublicKeyToken=null' due to value type mismatch.
If I copy the definition to my project so it shadows the original one, everything works.
The app.config has the following section:
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.4.1.0" />
</dependentAssembly>
And the projects files are updated with the directive <TargetFSharpCoreVersion>4.4.1.0</TargetFSharpCoreVersion>
So I am not really sure what can cause this error. What is also strange is that the error message claims that FSharpResult is supposed to reside in project assembly, rather than FSharp.Core.dll.
UPDATE. As suggested in the comments, the problem only occurs when the application is built using Visual Studio 2015. Here's a small console program that reproduces the problem:
open System
[<EntryPoint>]
let main argv =
let result = Result.Ok "Hello"
printfn "%A" result
0
Open Visual Studio 2015, build and run the project, you should see this error: Unhandled Exception: System.TypeLoadException: Could not load type 'Microsoft.FSharp.Core.FSharpResult`2' from assembly 'ResultTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' due to value type mismatch. at Program.main(String[] argv)
If you have Visual Studio 2017 and rebuild the app with it, the app will work fine and prints the result: Ok "Hello"