ASPNET Core pre-RC2 dependency ambiguity - asp.net-core

I am using:
.NET Command Line Tools (1.0.0-rc2-002439)
Product Information:
Version: 1.0.0-rc2-002439
Commit Sha: ef0c3b2cee
Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
RID: win10-x64
and getting:
error CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)' and 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)'
I suspect there are multiple OptionsModel assemblies (different versions) included on "dotnet restore".
The proof may be here:
The second suggestion with different parameter name:
Project.lock.json file has few interesting lines ("Infrastructure" is a referenced assembly):
"Infrastructure/1.0.0": {
"type": "project",
"framework": ".NETFramework,Version=v4.6.1",
"dependencies": {
"Domain": "1.0.0",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0",
"Microsoft.Extensions.OptionsModel": "1.0.0",
"Newtonsoft.Json": "8.0.3",
"WindowsAzure.Storage": "6.2.1"
},
"compile": {
"net461/Infrastructure.dll": {}
},
"runtime": {
"net461/Infrastructure.dll": {}
}
}
while the web application uses Microsoft.Extensions.OptionsModel/1.0.0-rc2-15914
Here is the configuration section of Infrastructure assembly:
"dependencies": {
"Domain": "1.0.0-*",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0-*",
"Microsoft.Extensions.OptionsModel": "1.0.0-*",
"Newtonsoft.Json": "8.0.3",
"WindowsAzure.Storage": "6.2.1-*"
}
The question is: why different versions (1.0.0 and 1.0.0-rc2-15914) are chosen while executing "dotnet restore"?
UPDATE: I tried changing project.json of Infrastructure project to "Microsoft.Extensions.OptionsModel": "1.0.0-rc2-15914" but I am still can't compile because of ambiguity displayed in screenshots. Are any assemblies cached somewhere on my computer?

The solution is:
Microsoft.Extensions.Options instead of Microsoft.Extensions.OptionsModel package had to be used in a referenced project.

Related

Why can't my Core 1 library be seen in my ASP.NET Core 1.0 (MVC6) project?

I have a little class library (Core 1), separate so that other apps may also use it, and all those reasons. It has only POCO model classes and a DbContext derivative. Its project file looks as follows:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"NETStandard.Library": "1.5.0-rc2-24027",
"System.ComponentModel.Annotations": "4.1.0"
},
"frameworks": {
"netstandard1.5": {
"imports": "dnxcore50"
}
}
}
Then I have an ASP.NET Core Web Application (.NET Core) that I wish to use the class library in. Nearly everywhere I look, and I've looked, says to just add the library to the main project's dependencies section of its project file. There it is, right at the top:
"dependencies": {
"WideWorld.Filing": "1.0.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
I can't even see the library namespace WideWorld.Filing in the main project, where I can, obviously, see its namespace, WideWorld.Office. I am very, very new to Core 1, and have only build monolith web applications before, so please excuse my ignorance if I'm missing something obvious.
If I do a package restore on the main project, I get three warnings in the log (and other stuff that looks harmless):
warn : Detected package downgrade: Microsoft.EntityFrameworkCore.SqlServer from 1.0.0 to 1.0.0-rc2-final
warn : WideWorld.Office (>= 1.0.0) -> WideWorld.Filing (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0)
warn : WideWorld.Office (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0-rc2-final)
The issue is that you're mixing packages versions. For example the RTM and RC2 packages are not compatible. You should either target everything as RC2 (which I'd advise against) or take the more preferred approach and upgrade all package references to RTM, targeting version 1.0.0.
More details here:
Note, I have omitted the "import": "dnxcore50"
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"NETStandard.Library": "1.6.0",
"System.ComponentModel.Annotations": "4.1.0"
},
"frameworks": {
"netstandard1.5": { }
}
}
Likewise, in the other project.json do this:
"dependencies": {
"WideWorld.Filing": "1.0.0.0",
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0"
Additional details on packages.

Adding Microsoft.EntityFrameworkCore.Tools to a ASP.NET Core project

I am creating a new ASP.NET Core project using dotnet 4.5.2 and am trying to add a reference to Microsoft.EntityFrameworkCore.Tools. In my project.json file I have these listed under dependencies:
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
Looking under References, they appear to be successfully loaded. I then added this under tools in project.json:
"Microsoft.EntityFrameworkCore.Tools": {
"imports": [ "portable-net451+win8" ],
"version": "1.0.0-preview2-final"
}
After I added that, when I build the solution I get this build error:
Could not find a part of the path 'C:\Users\(my user name)\.nuget\packages\.tools\Microsoft.EntityFrameworkCore.Tools'
I get the same error if I remove the imports line. What am I doing wrong here?
Just ran into the same issue.
I fixed the issue by installing the tools package again in the package manager console:
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
Before reinstalling the package was actually missing in the .nuget\packages.tools folder, after reinstalling it was there.
I followed the https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html tutorial, but I think I installed the package in the wrong order or initially forgot to reference the EF.tools package in the "tools" section of the project json.
I had this same problem and just solved using the examples from the EF Core setup guide from Microsoft, checking their GitHub code as well, I found this to work for the project.json.
I had to remove the imports from the "frameworks" property, which means no Application Insights for now. Once I did this and built, the folder appeared in the tools folder. Sorry I'm not good at posting code here but here are the important parts, ... elipses used to trim the post of my other things:
"dependencies": {
...
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
} ...},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
}...
I had the same issue and had to add the following to my project.json.
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0-preview1-final"
The only difference is that I'm working with the newly release .NET Core 1.1, ASP.NET 1.1 and Entity Framework 1.1.
I had the same issue and tried many things. I found out that Design and Tools need to be the same version but intellisense was not giving me options common to both packages. Then I found this article and tried its code.
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet
Using the following code from that article solved the issue for me;
"dependencies": {
"Microsoft.EntityFrameworkCore.Design": {
"type": "build",
"version": "1.0.0-preview2-final"
}
"Microsoft.EntityFrameworkCore.Tools": {
"type": "build",
"version": "1.0.0-preview2-final"
},
},
...
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
My problem was I had Microsoft.EntityFrameWorkCore.Tools instead of Microsoft.EntityFramework.Tools, note the lowercase w.

dotnet restore - "not compatible with win7"

I am attempting to use dotnet restore on a dotnet core project, and it seems to work fine until the very end, when I suddenly get this weird message.
error: System.IO.IsolatedStorage 4.0.1-beta-23516 provides a
compile-time reference assembly for System.IO.IsolatedStorage on
DNXCore,Version=v5.0, but there is no run-time assembly compatible
with win7-x64.
error: System.IO.IsolatedStorage 4.0.1-beta-23516 provides a
compile-time reference assembly for System.IO.IsolatedStorage on
DNXCore,Version=v5.0, but there is no run-time assembly compatible
with win7-x86.
I have searched high and low for answers to this, but I'm totally lost. I've posted my project.json below for reference, as well as my nuget.config feeds.
nuget.config feeds
<packageSources>
<add key="aspnet-core" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.0.1-*",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
"Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.0.0-*",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
"Microsoft.AspNetCore.Identity": "1.0.0-*"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Microsoft.AspNetCore.Mvc.Dnx": "1.0.0-*"
}
},
"net451": { },
"dnxcore50": {
"imports": "portable-net451+win7+win8",
"dependencies": {
"NETStandard.Library": "1.0.0-*"
}
}
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
Update
I have cleared the following directories;
%userprofile%\.nuget
%userprofile%\.dnx\packages
%localappdata%\NuGet\v3-cache
Then I ran the updater at /scripts/obtain/ from the dotnet/cli/ repository with the following command...
.\install.ps1 -channel beta
Then I went back and did dotnet restore on my project, it does say that it worked, but I get the following warning.
warn : Detected package downgrade: Microsoft.Dnx.Compilation.CSharp.Abstractions from 1.0.0-rc2-16553 to 1.0.0-rc2-16552
Is there anything I can do about that?
Your project looks totally fine and it restores without errors:
log : Restore completed in 69790ms.
NuGet Config files used:
D:\Temp\tempmvc\NuGet.Config
C:\Users\victor\AppData\Roaming\NuGet\NuGet.Config
Feeds used:
https://www.myget.org/F/aspnetcidev/api/v3/index.json
https://api.nuget.org/v3/index.json
https://www.nuget.org/api/v2/
Installed:
279 package(s) to D:\Temp\tempmvc\project.json
You might have some newer packages from other feeds in the packages caches or you might be using the wrong version of dotnet cli. Make sure you install the CLI from the beta channel.
To clear the caches delete:
%userprofile%\.nuget
%localappdata%\NuGet\v3-cache
To install the CLI from the beta feed, run the script from here:
install.ps1 -channel beta
The above answer is no longer valid with respect to the install.ps1 statement, but I cannot comment there:
The script name is now dotnet-install.ps1 and the parameters for channel are now: future, preview, and production with production being the most stable.
i.e.
dotnet-install.ps1 -channel production
EDIT: well for the moment -channel beta does still work and production does not exist yet, despite being listed in the source code :) the joys of pre-release software...

dotnet cli - "detected package downgrade"

I have finally managed to get a project's dependencies downloaded with dotnet restore, after going through the process of clearing all nuget cache, dnx cache, and updating the cli using the beta channel.
But using the project.json below, I get an error;
warn : Detected package downgrade: Microsoft.Dnx.Compilation.CSharp.Abstractions from 1.0.0-rc2-16553 to 1.0.0-rc2-16552
I'm not sure what this means, or how to fix it. The things still download, but this concerns me.
I am using the following;
dotnet/cli
.NET Command Line Tools (1.0.0-beta-001540)
Product Information:
Version: 1.0.0-beta-001540
Commit Sha: 6aeed1f52d
Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
Runtime Id: win10-x64
dnvm list
Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
1.0.0-rc1-update1 clr x64 win
1.0.0-rc1-update1 clr x86 win
1.0.0-rc1-update1 coreclr x64 win
1.0.0-rc1-update1 coreclr x86 win
1.0.0-rc2-16551 clr x86 win
* 1.0.0-rc2-16551 coreclr x64 win default
1.0.0-rc2-16551 coreclr x86 win
nuget.config
<packageSources>
<add key="aspnet-core" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.0.1-*",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
"Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.0.0-*",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
"Microsoft.AspNetCore.Identity": "1.0.0-*",
},
"frameworks": {
"dnx451": {
"dependencies": {
"Microsoft.AspNetCore.Mvc.Dnx": "1.0.0-*"
}
},
"net451": { },
"dnxcore50": {
"imports": "portable-net451+win7+win8",
"dependencies": {
"NETStandard.Library": "1.0.0-*"
}
}
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
One of the libraries explicitly require 1.0.0-rc2-16552 version, that's why you get the warning. Once the library u[grade to supports higher version warnings will disappear.
This is an old post so not sure which library is doing this at the time of your post, but for people with same warning, go through your libraries and look which one has version dependency.
Basically, remove the library or stay on downgraded version until the library updates and supports the new version.

VS2015 ASP.NET 5 beta7 dependency could not be resolved

This is a follow-up to this question. I started with an Empty ASP.NET project in VS2015 community, tried to add a couple packages based on a tutorial, and haven't gotten it to actually work yet. The initial problem in the linked question was due to some project dependencies using beta5 and some using beta7. Matching those up solved that, but now I get this error when I try to run the project in IIS Express:
Could not load file or assembly 'Microsoft.Dnx.Host.Clr' or one of its dependencies.
I think the problem is still version related--like the previous web.config assembly reference issues--but I don't know how to deal with it yet. I tried modifying global.json based on a similar issue I found on GitHub, but now it doesn't build. It looks like it can't find the newer version of the CLR I guess. From the Error List in VS2015:
The dependency Microsoft.AspNet.Mvc >= 6.0.0-beta7 could not be resolved.
The dependency Microsoft.AspNet.Server.IIS >= 1.0.0-beta7 could not be resolved.
The dependency Microsoft.AspNet.Server.WebListener >= 1.0.0-beta7 could not be resolved.
global.json:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta7",
"runtime": "clr",
"architecture": "x86"
}
}
My project's References tree has yellow error indicators but looking in the NuGet package manager for my project doesn't show any upgrades (or anything installed at all, as far as I can tell).
dnvm list:
1.0.0-beta5 clr x64
1.0.0-beta5 clr x86
1.0.0-beta5 coreclr x64
1.0.0-beta5 coreclr x86
* 1.0.0-beta7 clr x86 default
1.0.0-beta8-15585 clr x86
dnu list:
Microsoft .NET Development Utility CLR-x86-1.0.0-beta7-15532
I've restart VS but that didn't help. Changing back to beta5 in my global.json makes it compule successfully but then I get the IIS error.
project.json:
{
"webroot": "public",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"public",
"node_modules",
"bower_components"
]
}
package.json:
{
"version": "1.0.0",
"name": "ASP.NET",
"private": true,
"devDependencies": {
"angular2": "2.0.0-alpha.36",
"gulp": "3.9.0"
}
}
"To use ASP.NET 5 beta7 with Visual Studio 2015, you will need to download and install the beta7 version (14.0.60831.0) of ASP.NET and Web Tools 2015."
http://go.microsoft.com/fwlink/?LinkId=623894
https://github.com/aspnet/Home/releases