I am unable to reference FSharpOption<> within my C# PCL project targeting Xamarin.Android within Visual Studio 2015.
Here's a video that shows the steps of me attempting to resolve it.
The error I receive is the following:
The type FSharpOption<> is defined in an assembly that is not referenced. You must add a reference to assembly
FSharp.Core, Version=3.7.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
NOTE:
My C# project DOES reference FSharp.Core. It is referencing the same FSharp.Core version that my F# projects are using:
some_path\packages\FSharp.Core.4.0.0.1\lib\portable-net45+monoandroid10+monotouch10+xamarinios10\FSharp.Core.dll
Adding an App Config
The app.config file that I placed in my Android client project is the same app.config file that I am using in my test project that's written in F#.
The app.config is 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="0.0.0.0-999.999.999.999" newVersion="4.4.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Can anyone provide me guidance on the steps required to reference FSharp.Core functionality within my C# project?
UPDATED
I have another class that successfully references FSharp.Core within the same C# project:
static class Utility
{
public static bool IsSome(this FSharpOption<string> option) => FSharpOption<string>.get_IsSome(option);
public static bool IsNone(this FSharpOption<string> option) => FSharpOption<string>.get_IsNone(option);
}
The code above does not appear to cause any compile errors. Again, this file is in the same project as my other file that does cause errors.
The code that causes errors is the following:
using Microsoft.FSharp.Core;
// . . .
if (_viewModel.FamilySummary.IsSome()) {
}
NOTE:
The using statement for FSharp.Core appears to be ignored.
My viewmodel is hosted within an F# project inside Visual Studio.
When I run into similar issue the solution was to uninstall FSharp.Core from both projects (the C# and the F# one) and then install it again but using the NuGet package manager for the Solution (not individually for each project).
So after removing FSharp.Core from both go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution...
There search for FSharp.Core, tick all the projects you want to add the library to and select the version you want to add.
That solved this issue for me.
Edit: The other thing worth checking is that any library that is using FSharp.Core is actually using the same version as the one you installed.
After changing binding redirects in app.config, you may also need to delete the obj folder under the executable project folder.
For some reason an outdated config file can hang around in there and get copied to your bin folders, despite performing clean rebuilds.
I resolved my issue by adding the actual DLL file to my client project and then had my client reference that dll.
Related
I can not use the SqlType provider due to an issue with Microsoft.Bcl.AsyncInterfaces.
I am using a minimal program with .NET 4.7.2 and F# 4.7.0.0.
My Nuget packages contain a reference to:
package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0"
targetFramework="net472"
Severity Code Description Project File Line Suppression State
Error FS3033 The type provider 'FSharp.Data.Sql.SqlTypeProvider'
reported an error: Unable to load one or more of the requested types.
Retrieve the LoaderExceptions property for more information. Details:
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or
one of its dependencies. Das System kann die angegebene Datei nicht
finden. TestSqlProvider C:\Users\weism\source\repos\TestSqlProvider\TestSqlProvider\Program.fs 9 Active
What can I do to fix this issue?
For me, installing the Microsoft.Bcl.AsyncInterfaces (Nuget package) fixed the issue.
This error also happens when you try using Microsoft.EntityFrameworkCore v5 in a dotnet core v3.1 project.
To resolve, down-version Microsoft.EntityFrameworkCore to latest v3 version.
For .Net Core, This problem basically occur , when we use layered architecture. Just make sure the version of Microsoft.EntityFrameworkCore should be same in all project, wherever it is used.
I don't use Microsoft.Bcl.AsyncInterfaces at all in my .NET 4.8 project. Some library depends on version 1.0.0.0. I resolved the issue using a binding redirect:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
Microsoft.Bcl.AsyncInterfaces.dll 5 was copied to Bin after build.
I think you update package in one layer.
for me i worked in project with three layers (api, AdminTool, Data) the AdminTool Layer had a reference to Data Layer i updated all packages in AdminTool only so i had this error i update package also in data layer and api layer so the problem solved.
I hope that help you.
My Entity Framework Core just needed upgraded
TO
Make sure you have unique single version of that dll. Another step would be to add a binding redirect in the app.config as told in the above comments.
Check in your installed nuget packages---
If version of Microsoft.EntityFrameworkCore and your .net project is different then it can be a problem.
Example - If EntityFrameworkCore is at v5.1.5 or higher & your project dotnet core v3.1 project, this can be the issue.
To solve,
down-version Microsoft.EntityFrameworkCore to equal version of project such as v3 version. to down version click on tool in visual studio -->Nuget Package Manager--> Manage Nuget package for Solutions --> click on installed ---> select nuget package which you want to downgrade --> click on uninstall and then select the same nuget package and then install version 3.1.5 or relevent package.
or
Install Microsoft.Bcl.AsyncInterfaces (Nuget package)
Updating the Microsoft.Bcl.AsyncInterfaces assembly via NuGet did everything it needed to do, including adding the bindingRedirect entries in the appropriate config files.
I also did all the other hygienics. I cleaned my solution, deleted the bin and obj directory entries, and also cleaned my localhost deploy locations.
However, I still got this error. I reviewed the output (my application is a .NET 4.8 MVC Web application, so the web page showed the error log in detail), and I found that it was failing on loading SimpleInjector.
I updated SimpleInjector to the latest version via NuGet and that fixed my error.
Unfortunately, I didn't keep a copy of the error page, so I can't show you what I saw, but the bottom line is to examine the output or log in detail, see if you can find where the application is attempting to load the assembly that is failing, and update that assembly that appears to be calling the load.
I was able to fix it by removing <Private>True</Private> from csproj for Microsoft.Bcl.AsyncInterfaces. Just reinstall this NuGet package
There is a problem – only when I request one single controller – I get the exception:
Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040
It's strange because in my config file I see that the version is 4.0.0.0 and and all the other controllers are fine and only when I upload the application on the server this thing happens.
This is a known issue. Seems you have migrated recently from 3.0 to 4.0 or this application is a fresh clone from the repository. The one single controller may not have nuget restored. I have also faced this issue. I got this msdn link and browsing it had a solution. Here are the steps mentioned.
The problem can be resolved by implementing one of the following
solutions:
(Preferred) Install Microsoft.AspNet.Mvc from the NuGet gallery (this will install a binding redirect in your web.config). You can do
this from the NuGet package manager or the NuGet console inside Visual
Studio:
Install-Package Microsoft.AspNet.Mvc -Version -Project PROJECTNAME
MVC 4 version: 4.0.40804.0
MVC 3 version: 3.0.50813.1
Manually update the reference to System.Web.MVC.dll (don’t use the one in the GAC).
Try the Add Reference -> Assemblies -> Extensions dialog box.
In either case ensure that the Copy Local project property for the
assembly is set to true so it ends up in your bin folder which is
needed for deployment. There is a known NuGet bug that resets the Copy
Local flag: https://nuget.codeplex.com/workitem/4344
Install Nuget Package Microsoft.AspNet.Mvc for all the project referencing System.Web.Mvc dll Hope this solves your problem
I got this build error on a VSO agent thanks to the ASP.Net assembly resolve weirdness. I had changed some of my build configurations and Visual Studio modified the output directory for the MVC project to \bin\x86\Debug or something similar.
This had bitten me before and I remembered ASP.Net wants to be built to \bin ONLY.
So when you get any kind of "reference could not be found" on build time, remember to check that your build output directory is only \bin:
More on the problem here:
Changing output directory for asp.net project in Visual Studio
Hope this helps someone.
You maybe can reference ASP.NET MVC as reference to GAC, but it can happens that different developers have different version of MVC installed.
Remove references to ASP:NET MVC and add ASP.NET MVC as nuget package.
Go to Nuget manager, search for: "Microsoft.AspNet.Mvc", and press update button.
That work on my case.
I got this also at run-time, and it was due to my project (a unit test project using NuGet PackageReference) referencing an ASP.NET website project that already had the necessary binding redirects in place (as suggested by the compiler warnings when building). I had to add the same binding redirect in the unit test project.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.6.0" newVersion="5.2.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
We have a WCF webservice that is targetting .NET framework 4.0. This WCF, uses a assembly from the same Visual Studio project that in turn uses a couple of Nuget Packages like so below:
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" />
This Nuget package is adding two assemblies to the "System.Net.Http" and "System.Net.Http.Formatting" to the project. When this application is getting deployed using TFS Build, for some reason these two assemblies are not getting copied to the bin folder on the server. When I check the "Copy Local" flag for these two assemblies, I see that they are set to TRUE.
I have uninstalled the Nuget packages and installed it again, but doesn't seem to work.
Any suggestions as to what could be wrong?
we're using VSO hosted build controller to run our CI builds. A build has started failing that was working fine.
C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets (1697): Could not resolve this reference. Could not locate the assembly "Microsoft.WindowsAzure.Diagnostics, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
This assembly should resolve to the Azure SDK which should be included in the host according to http://listofsoftwareontfshostedbuildserver.azurewebsites.net/ although http://www.visualstudio.com/en-us/get-started/hosted-build-controller-vs.aspx states the host only supports upto 2.3. We have had this building though.
All our assemblies for Azure SDK are for version 2.4. It builds locally and there are no previous versions of the SDK installed on my machine. We have binding redirects like so...
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.Diagnostics" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.4.0.0" newVersion="2.4.0.0" />
</dependentAssembly>
Has anyone else seen this?
You can fix this by setting the "Specific Version" property in your Microsoft.WindowsAzure.Diagnostics reference in the affected project, using Visual Studio (right click on the reference and choose Properties in Solution Explorer). This will cause the build server to use the 2.3 version of the assembly.
If you're using any new classes or methods in the 2.4 SDK this might not work but it at least gives you a temporary solution until MS gets the problem fixed.
Here's a picture of my working reference
Finally, check out the link (Really old) for more info on specific reference version: http://www.codemag.com/article/0507041,
I started experiencing same today. Not sure what has changed.
Following was raised https://connect.microsoft.com/VisualStudio/feedback/details/1007907/error-deploying-to-azure-sdk-2-4
What I did to overcome this issue is that I created old style lib folder, and added diagnostics and runtime dll to it. I change my csproj to reference from there. And this seem to have fixed it
The bug is now fixed. A workaround is no longer required to use Azure SDK 2.4.
I added a powershell script to print out all libraries on the build server. A full guide on this can be found here. The script consists of the following line
gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
The Windows Azure Libraries for .NET - v2.4 was missing from the printed list, all other versions are available. This has been raised as an active bug on connect.microsoft.
Until this is fixed adding the 2.4 libraries to source or reverting to an earlier version of azure will be the only work around.
I am trying to install Unity.Mvc4 but I get this error message;
Could not load file or assembly 'Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
The version of Microsoft.Practices.Unity I have is 3.0.0.0. Why would I want an older version?
Unity.Mvc4 is a community project and references an older version of Unity. If you want to use Unity.Mvc4 you can get an older version of Unity from the Package Manager Console you should use the following (see this post for more information)
Install-Package Microsoft.Practices.Unity -Version <press tab key for autocomplete>
From personal experience: If you want or need to use newer versions of Unity (which has good support for MVC and Web API in version 3) you should try to get rid of packages like Unity.Mvc4 or Unity.WebApi. They are useful for older projects (where Unity 3 is not a choice), but for new projects Unity has all you normally need.
I had a similar problem with Unity 3. Instead of installing another version of unity I just changed the assembly binding in the web.config:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>