Specify dependencies for inclusion in nupkg - f#

I'm trying to release a library on nuget, but when trying to install it, it says that it can't find the dependency.
I'm using paket and a paket.template in order to generate the nupkg. I have no real idea how dependency resolution happens in F#/.NET, but it looks like in my .fsproj file, it's referencing a relative path.
The dependency I'm trying to include is Colorful.Console.
In my .fsproj, it references it like:
<Reference Include="Colorful.Console">
<HintPath>..\packages\Colorful.Console\lib\net461\Colorful.Console.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
which works fine locally, and seems to have no apparent problems during paket pack, but when installing in a different project from the remote source (also using paket), it tells me that MyLibrary can't find dependency 'Colorful.Console'.
It's in my library's dependencies with nuget Colorful.Console, and that dependency seems to be carried through, as Colorful.Console is in the packages folder of my other project (and shows up under 'References' in Visual Studio).
I've included the example project here: https://github.com/deecewan/GenbankDemoProject
Here is the library project, and more directly the paket.template used to generate the package.
Edit: I have updated my project thanks to advice from #rmunn - it is now meant to load the Colorful.Console version from net461 when the framework is net472. This is what I want/expect, I think. However, I still get the following error:
parse error FS3053: error : The type provider constructor has thrown an exception: Could not load file or assembly 'Colorful.Console, Version=1.2.9.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Attached below is a screenshot of the references of the project - GenbankTypeProvider and Colorful.Console are both included.

Related

Could not load file or assembly Microsoft.Bcl.AsyncInterfaces

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

Wrong version of mscorlib being added by build after upgrade (An attempt was made to load a program with an incorrect format)

I'm working on a project that was recently upgraded to Sitecore 8.2 and .NET framework 4.6 from 4.0. When I build it locally my site works, but in my testing environment, where I'm building in Jenkins using msbuild, the mscorlib dll is causing is causing a compilation error:
Could not load file or assembly 'file:///E:\inetpub\wwwroot\mysite\Website\bin\mscorlib.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
There is no reference to mscorlib in my project, as this dll is referenced automatically by the build system, so I'm not sure how to modify or update it.
The line in the MSBuild logs where it's being added:
Copying file from "C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" to "bin\Release\mscorlib.dll".
Furthermore, when I build my project in Visual Studio, it does NOT copy mscorlib.dll into my bin, so I'm not sure why this is happening in the Jenkins build and not my local environment.
By default it was adding the dll from C:\Windows\Microsoft.NET\Framework\v4.0.30319\ and I needed it to use the version in C:\Windows\Microsoft.NET\Framework65\v4.0.30319\ instead. I added a reference to the csproj file with the correct path:
<Reference Include="mscorlib">
<HintPath>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll</HintPath>
</Reference>

System.IdentityModel.Tokens.Jwt version mismatch on Nuget packaging

Could not load file or assembly 'System.IdentityModel.Tokens.Jwt,
Version=4.0.0.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)
I have somehow returned to DLL hell.
I have an asp.net MVC app that I want to deploy via our CI:
TeamCity (2017.1.3) with the Octopusplugin (TeamCity Plugin)
Octopus deploying to azure website app
I've gotten this same pipeline to work for other web apps, but for this one MVC app that utilizes System.IdentityModel.Tokens.Jwt, version 4.0.4.403061554.
I run the app locally, and the FileAssembly version referenced is 4.0.4.403061554 as expected. However, when team city builds the nuget package, and I download and extract it, the System.IdentityModel.Tokens.Jwt file assembly version is set to 5.1.4.216 which is not what I am expecting.
I've drilled through all of my packages deplendencies, none are referencing this version of the dll.
I have searched through all of my files for any refernece of 5.1.4, nothing exists.
I have also checked the feature to Disable looking up packages from local machine cache when refreshing packages in TeamCity.
There is not a straight answer here, however a couple thoughts which could hopefully help in the right direction.
Maybe there is a lower level dependency to this package in any other project or nuget package, which gets built together and as a result the latest version gets into build directory? Just noted that the 5.1.4 is the latest version of System.IdentityModel.Tokens.Jwt.
I presume you employ BindingRedirect to version 4. Have there been braking changes? Could you not switch to using the latest version?
Have you looked in the build folder of the build server? Maybe you could narrow down the project/folder with the version 5.1.4?

NuGet - dependency installed but not found

I have a problem with the NuGet package manager. I published my library (a type provider, but I don't think this matters) and then testet it, but it fails to find a dependency. The complete error message is (full namespace/name ommitted for brevity):
The type provider 'TypeProviderImplementation....' reported an error:
Could not load file or assembly 'dotNetRDF', Version=1.0.3.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies.
The thing is that when installing the library, it looks like the dependencies are installed correctly. The correct libraries are downloaded and there is no error showing up.
In an attempt to solve the problem, I specified the exact version in the .nuspec file, but this didn't change anything.
...
Installing dotNetRDF via NuGet and then manually referencing my precompiled DLL (without going through NuGet) seems to work fine.
So I'm basically out of ideas on how to solve or even debug the problem. I'm thankful for any pointers.
Addign more information about .NET version numbers as my comment below is quite hard to read:
I checked framework versions as suggested. I did this via looking at the FrameworkDisplayName in the object browser. Basically, my library was using 4.5 and dotNetRDF was using 4.0.
I switched to .NET 4.0, but nothing changed.
My library = ".NET Framework 4"
dotNetRDF = ".NET Framework 4"
HtmlAgilityPack = ".NET Framework 4.5"
Newtonsoft.Json = ".NET Framework 4.5"
VDS.Common = ".NET Framework 4 Client Profile"
My dependency is dotNetRDF, the remaining ones are dependencies of dotNetRDF.
Latest NuSpec file can be found here. I create the package via the command nuget pack LITEQ.fsproj -Prop Configuration=Release.
The package id is LITEQ.RDF.
Some additional information:
The library is a F# project. I just tested what happens if I create a console project and install the library via NuGet and then send the references to the F# Interactive Console. It actually works in this case.
So it feels like there is some problem with the project configuration after installing the library via NuGet.
To reproduce, the error, download the library, open up the UniKo.West.Liteq namespace and for example use the NpqlTypeProvider:
open Uniko.West.Liteq
type A = NpqlRdfProvider< #"">
Certainly for me I can't see any obvious problems, when I install your package into an empty console project I don't have any issues and I can write a trivial example that uses the dotNetRDF APIs just fine. If you can produce a minimal example project into which installing the packages creates an issue then that would be very helpful.
Your Issue
However the dependencies you state for your project look wrong, you have .Net 4.0 for your project and some dependencies but .Net 4.5 for others which will not work. Note that when you downgrade a projects target framework NuGet does not cope nicely with that, it is best to completely uninstall and reinstall NuGet packages any time you change the target framework version. It is perfectly fine for a newer version of the framework to rely on dependencies that target older versions, so your .Net 4.5 project can happily depend on the .Net 4.0 version of dotNetRDF. However the reverse is not true which may be the cause of your problems.
You can sometimes tell if this is the case because VS may highlight bad dependencies under References in the solution explorer with little warning icons (sadly it doesn't always do this). Even if this is not the case you should see output like the following in the Output Window when you try and build if you have incompatible dependencies and this may also yield compile errors about missing namespaces:
C:\Program Files
(x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5):
warning MSB3274: The primary reference "HtmlAgilityPack" could not be
resolved because it was built against the ".NETFramework,Version=v4.5"
framework. This is a higher version than the currently targeted
framework ".NETFramework,Version=v4.0".
So I would strongly suggest that you uninstall all packages via NuGet and reinstall them whenever you change the target .Net framework of your project.
Other Issues
In terms of other possible issues you are using dotNetRDF 1.0.3 which is not the latest version, versions prior to 1.0.5 have a known issue related to interactions with the versioning and framework profiles of Json.Net. If a project you are installing into also has dependencies on Json.Net you may run into version conflict issues. See CORE-405: Resolve Issues with Json.Net dependency for some discussion on this.
I would suggest that you also upgrade your dependency to the latest dotNetRDF release which is 1.0.6.3421 at the time of writing this answer and see if that resolves your problem.
Edit - NuGet Package Versions
NuGet packages versions do not have to correspond to the assembly version, as it happens 1.0.6.3421 does have an assembly version of 1.0.3.0. That was actually not our intention but a flaw in our build process but that isn't really relevant here.
What it looks like is that your library is compiled against a different version of dotNetRDF than the one NuGet is installing for you. However without seeing the source of your package it is impossible to debug further.
What if neither solution works?
If neither of these things resolves your problem then you are going to need to provide a minimal project that reproduces the problem.
A temporary solution (or more of a hack) is to not rely on dependencies, but to directly put the DLLs into the NuGet package. When I do this, the library works fine. The NuSpec file in this case looks like this (excerpt):
<package>
<metadata>
...
</metadata>
<files>
<file src="bin\Release\dotNetRDF.dll" target="lib/net40" />
<file src="bin\Release\HtmlAgilityPack.dll" target="lib/net40" />
<file src="bin\Release\HtmlAgilityPack.pdb" target="lib/net40" />
<file src="bin\Release\HtmlAgilityPack.xml" target="lib/net40" />
...
</files>
</package>
But obviously, this isn't a good solution.

Sharp Architecture - NewtonSoft.Json assembly mismatch

Create a fresh Sharp Architecture project.
Successfully build, create DB, run Web app.
Attempt to add a new entity to the database via the web View.
Get the error:
Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Issue:
The Newtonsoft.Json package was not updated due to the -Safe param added in the Sharp Architecture instructions
Solution:
Manually update the NewtonSoft.Json package via the Package Manager Console:
Update-Package Newtonsoft.Json
Update the binding references for each project that includes that package via the Package Manager Console:
Add-BindingRedirect

Resources