Avery B
Avery B

Reputation: 237

Conflicting Versions of the Same Assembly

I am creating an F# project in Visual Studio, and I get the following warning for every .fs file in the project:

warning FS0082: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="FSharp.Core" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" /></dependentAssembly></assemblyBinding> (Code=MSB3247)

warning FS0082: No way to resolve conflict between "FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily. (Code=MSB3243)

I have thoroughly read a few posts that deal with this same problem, but I am still having trouble solving the issue. In every case I have seen, the issue deals with a package that is installed through NuGet. These cases can be handled by just un-installing and then re-installing and re-referencing the package. However, as FSharp.Core is a built-in package that cannot be uninstalled, I have no idea how to combat this issue. Any help would be appreciated.

EDIT (in response to Mark's answer):

I took a look at my app.config file, and at first it looked like the following:

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

Then, I modified it to look exactly like the answer below. Unfortunately, I was still getting the same error messages as posted above. I then noticed some slight structural differences between the code in my app.config file and the one posted below, so I moved the redirect into my original config file to look like the following (basically replacing the three binding redirects with the one):

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

Unfortunately, I still continue to have the same warning messages when I run the program. I'm not sure if this is the issue, but the example in the link seems to deal with a FileNotFound exception, while my build appears to be able to find both files when it really needs only one. But, I really don't know that much about F# or Visual Studio, so that difference could be irrelevant.

Upvotes: 3

Views: 1512

Answers (2)

Anton Schwaighofer
Anton Schwaighofer

Reputation: 3149

In response to Avery's edit:

I've had similar problems with projects that involve different versions of FSharp.Core. The key problem is that VS does not always correctly binplace FSharp.Core.dll. What most likely happened is:

  • Your project output directory contains FSharp.Core.dll - some version of it.
  • You build your project. Thanks to the assembly redirect, the referencing errors are gone. All code is built against version 4.3.1.0
  • The built assembly is placed in the output directory. FSharp.Core.dll is not binplaced again, VS thinks it is already there.
  • You run the code. At that point, it finds the wrong version of FSharp.Core.

The solution would be to clean the project output directory before build. Implicitly you did that by creating a new project, after which you saw everything working fine.

I generally now create all of my F# projects with .props files that include FSharp.Core. That props file is shared across all projects in my repository. If there's a language upgrade, I only need to change the props file and have all my projects use a consistent version of FSharp.Core.

Upvotes: 1

Mark Seemann
Mark Seemann

Reputation: 233497

Assuming that you have F# 3.1 installed, here's how you can redirect FSharp.Core 4.3.0 to FSharp.Core 4.3.1:

Add this to your app.config or web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral"/>
        <bindingRedirect oldVersion="4.3.0.0"
                         newVersion="4.3.1.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Upvotes: 3

Related Questions