Ambiguous Call when using Should().NotBeNull() on As item - fluent-assertions

When I do the following test
var contentRes = res as OkNegotiatedContentResult<List<MachineHealthTableDTO>>;
contentRes.Should().NotBeNull();
I get the error
The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should<TDataRow>(TDataRow)' and 'DataSetAssertionExtensions.Should<TDataSet>(TDataSet)'
This started happening when I upgraded from fluent assertions 5 to 6.
Any Idea as to how I can go about resolving this issue would be appreciated.

I had a very similar issue with an enum
actualEnumValue.Should().Be(expectedEnumValue);
with the error
Error CS0121 The call is ambiguous between the following methods or properties: 'DataRowAssertionExtensions.Should(TDataRow)' and 'DataSetAssertionExtensions.Should(TDataSet)'
I finally managed to solve the issue by removing <LangVersion>7</LangVersion> from the project file.

I've just had this exact issue with a .NET Framework 4.8 console app. Would build fine locally but failed the build step in the Azure DevOps pipeline.
Turns out that pipeline was using the vs2017-win2016 vm. Bumping it up to windows-2019 - which used Visual Studio 2019/later version of MSBuild - sorted the issue.

As a quickfix for the failing build I changed the extension method to
AssertionExtensions.Should(contentRes).NotBeNull();

The question has already been answered, but I had this same error message and could not understand why FluentAssertions had made so many changes from 4 to 6 version. Turned out, I had multiple versions of the Nuget package installed. So check via "Manage nuget packages" for solution, if you have multiple versions of the Fluent Assertions nuget package installed. See the consolidate tab in Visual Studio.

Related

Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=5.0.0.0 in Azure Functions

I have an API and a separate Azure Functions app. I upgraded my API app to .NET 5 and it's working fine. In the API app's solution, I have class library projects that I also reference in my Azure Functions app. These class libraries are netstandard2.1 projects.
Ever since this update -- during which I also updated all my NuGet packages to latest versions -- my Azure Functions app stopped working. I'm getting the following error:
Could not load file or assembly
'Microsoft.Extensions.Configuration.Abstractions, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot
find the file specified. Value cannot be null. (Parameter 'provider')
I noticed that there were breaking changes involving the Microsoft.Extensions.* packages and their recommendation is to install the package that is causing the issue directly. So I added Microsoft.Extensions.Configuration.Abstractions to my Azure Functions manually -- before it was being installed as a dependency of Microsoft.Extensions.Configuration package. Here's the information about this:
https://github.com/dotnet/aspnetcore/issues/21033
The issue still persists. I even tried downgrading Microsoft.Extensions.Configuration in both the API and Functions app, but I'm still getting the same error.
Any idea how to resolve this issue?
Sam's comment should be accepted as correct answer. I try it out to downgrade Microsoft.Extensions* (in my case Microsoft.Extensions.Logging.Console) from 5.0.0 to 3.1.0 and the error just gone.
Bravo!
If you are upgrading from .NET Core 3.1 to .NET 6 and you get this error, you need to change the Azure functions version to v4 and it fixes this error.
As a reference, this GitHub link explains exactly why that happens.
And as of now, you either track down the exact versions been referenced or downgrade everything to the latest v3 build.
In a nutshell, Azure Functions SDK already has some dependencies loaded in memory, so your libraries cannot use newer versions of the same libraries.
Adding this answer in case it helps anyone upgrading from .NET 3.1 to .NET 6.0.
First, as per #Jeff's answer, make sure you reference v4 in the Azure Functions project .csproj file:
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
In my case, however, this was already set.
The Azure Function was running fine locally however in Azure DevOps pipeline I was getting the error described by the OP.
I noticed that when debugging the Azure Function locally, the console was outputting:
Azure Functions Core Tools
Core Tools Version: 4.0.3928 Commit hash: 7d1d4a32700695bbf290a871c7492fde84bb767e (64-bit)
Function Runtime Version: 4.0.1.16815
In my case I am actually running the Azure Function in an Azure DevOps pipeline for e2e test purposes. To achieve this, I first install the Azure Function Core Tools on the build agent using this npm command:
npm install azure-functions-core-tools -g
However this installs azure-functions-core-tools#3.0.3904 (version 3.x - NOT the latest version 4.x).
I then installed Azure Function Core Tools (v4), e.g. by installing with this npm command.
npm i -g azure-functions-core-tools#4 --unsafe-perm true
And this (for me) resolved the error.
Whether or not this is your exact scenario, make sure you are using Azure Function Core Tools v4.x if using Azure Function Runtime v4 and .NET 6.
As #binaryDi mentioned in their answer, you need to downgrade packages that reference version 5 of Microsoft.Extensions.Configuration.Abstractions.
This can be a bit of a pain, as it doesn't tell you which packages are actually referencing Microsoft.Extensions.Configuration.Abstractions package/namespace.
For me, I had to update Microsoft.Extensions.Caching.Memory and Microsoft.EntityFrameworkCore.SqlServer to a version before 5. Anything that is referencing dotnet 5 should be downgraded for the Azure Function to run.
I stumbled upon this question while looking for an answer to my problem with upgrading to .NET 6.0. There was no going back, because I've bought a Macbook with an M1 processor and Arm support only works decently in .NET 6.0
Putting <AzureFunctionsVersion>v4</AzureFunctionsVersion> wasn't enough, because that doesn't increase the runtime version on Azure.
My function was already running on version 3.0 and strangely I couldn't select v4.0 in the portal. I had to change the version through the Azure CLI.
More information on how to do that can be found here: https://learn.microsoft.com/en-us/azure/azure-functions/set-runtime-version?tabs=azurecli
I also ran into this error when upgrading a c# function project from NETCORE 3.1 to .NET 6.
I set the following in the project (.csproj).
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
AND also changed the Application setting value in the Function App - Configuration Section (Azure Portal)
"FUNCTIONS_EXTENSION_VERSION" from "~3" to "~4"
and that fixed it for me.
I also ran into this error when upgrading a c# func project from version 3 to 4.
I had already set <AzureFunctionsVersion>v4</AzureFunctionsVersion> but that didn't solve it.
The answer by #neeohw pointed me to the solution that fixed it for me, but I had to dig a bit further, and this is what fixed it for me:
Do the Azure cli commands as specified here:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-csharp#azure
I suggest you read that section for a background understanding, but the commands that ran was these:
az functionapp config appsettings set --settings FUNCTIONS_EXTENSION_VERSION=~4 -n <APP_NAME> -g <RESOURCE_GROUP_NAME>
# For Windows function apps only, also enable .NET 6.0 that is needed by the runtime az functionapp config set --net-framework-version v6.0 -n <APP_NAME> -g <RESOURCE_GROUP_NAME>
The issue was occurring to me, when I was trying to host an upgraded function in Azure functions. The previous version was targeted to netcoreapp3.1, which I upgraded to target net6.0 and, set v4 as Azure Function version.
The error was
"Could not load file or assembly 'Microsoft.Extensions.Configuration', Version=6.0.0.0 in Azure Functions"
After spending couple of hours, I figured that its the startup class that was causing the issue because it was the only place Configuration was used.
Changing the Startup to inherit from FunctionsStartup rather than WebJobsStartup, fixed the issue.
And with slight adjustments, it worked.
[assembly: FunctionsStartup(typeof(Startup))]
...
public class Startup : FunctionsStartup { ...
public override void Configure(IFunctionsHostBuilder builder)
{
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddHttpClient();
...
}
That's it!
I had the same issue and the configuration for Azure FunctionsVersion was already present.
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
I was able to resolve the issue by downgrading the version of Microsoft.Extensions.Http from 7 to 6
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
I was this error on my Mac (arm) when I tried to ran my functions (.NET6) locally.
In my case, I tried your solution and the functions still would not start and I still had this log in the console: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified..
I realized that I had installed 2 instances of azure tools (v3 with HomeBrew and v4 with npm).
When I run func start to start my functions, I observed that v3 was used. So I uninstalled the v3 tools with HomeBrew to use v4 with npm).
In my case, the reason was Microsoft.EntityFrameworkCore version 5.0.2.
I donwgraded it to version 3.1.18.
(Other related packages, such as Microsoft.EntityFrameworkCore.Design, Microsoft.EntityFrameworkCore.SqlServer, and Microsoft.EntityFrameworkCore.Tools should also be downgraded to 3.1.18.
I had this error when I used the latest of version Npgsql.EntityFrameworkCore.PostgreSQL which is 5.0.7 as this time of writing. I had to downgrade to 3.1.11 for the current version has a dependency to the 5.0.0.0 version of
Microsoft.Extensions.Configuration.Abstractions.

What is the correct package to use for SIgnalR with ASP.NET Core?

I'm trying to use SignalR in an ASP.NET Core web application but I'm struggling to find the correct package to use. In this article, they say to use "Microsoft.AspNetCore.SignalR" (with the help of a NuGet.Config file) but when I do a dotnet restore, I get:
error NU1102: Unable to find package Microsoft.AspNetCore.SignalR.Server with version (>= 0.2.0)
error NU1102: - Found 1 version(s) in nuget.org [ Nearest version: 0.0.1-alpha ]
error NU1102: - Found 0 version(s) in aspnetcidev
I guess the v0.0.1-alpha is not the one I want.
However, I found the package "Gray.Microsoft.AspNetCore.SignalR.Server" and it seems to work but the last published version is from November 2016... That, and the namespace make me think that it's not the package I have to use neither...
I also saw this video that refers to the v1.0.0 version but, of course, I can get it to work...
Anyway, what is the correct package to use in order to use SignalR?
I'm using the prerelease dev package for now.
https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json (thank you Pawel)
I also had to get the Microsoft.Extensions.Primitives from there.
Update:
I had to go back to .NET core 1.1 packages since migrating to 2.0 will not work for several reasons. I went back to using the unmaintained Microsoft.AspNetCore.SignalR.Server Version 0.1.0 from here:
https://www.myget.org/F/aspnetmaster/api/v3/index.json
Update:
For a new project I'm successfully using the v.1.0.0-alpha2-final version from nugget.org.
Examples including the JavaScript files can be found here: aspnet/SignalR-samples

How to setup a TeamCity build for a ASP.NET 5 project

I'm trying to setup a CI server for a website that I'm developing, but I can't find any info regarding how to do it with the new ASP.NET 5.
I got you brother. This took me a few days to figure out. This configuration is on TeamCity v10 for a ASP.NET Core 1.0 RC2/preview2 project. As a bonus, I am including the step where it pushes to Octopus Deploy. You will need to install the dotnet teamcity plugin and the newest Octopus Deploy plugin with Push functionality. Here's an overview of the build steps:
First off, don't try to use dotnet restore to restore the packages. It won't work if you have internal nuget packages that are not compiled as .Net Core. This took forever to figure out. I would ignore trying to use dotnet restore until people have converted everything over to .Net Core or Microsoft fixes dotnet.exe to be more flexible.
Some of the stuff I read said to use the newest beta version of NuGet, 3.5. When I tried this, I would get the following error.
[14:30:09][restore] Starting NuGet.exe 3.5.0.1737 from D:\buildAgent\tools\NuGet.CommandLine.3.5.0-rc1\tools\NuGet.exe
[14:30:10][restore] Could not load type 'NuGet.CommandAttribute' from assembly 'NuGet, Version=3.5.0.1737, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
I don't know what that means, and I don't care. Use 3.4.4 for now. Fill in the rest as appropriate.
The dotnet publish step is pretty straightforward. Make sure you provide the output directory because you want to use it in the final step. Also, be sure to specify an absolute path by using the %teamcity.build.workingDir% variable because of this bug. Otherwise it will fail to find your web.config file and not finish publishing the entire site. You'll be missing things like web.config and wwwroot!
Finally we Push to Octopus. This was very tricky for me. Note the part that says
%teamcity.build.workingDir%/published-app/**/* => OrderReviewBoard.1.0.0.zip
IF ANY PART OF THIS IS INVALID, YOUR STEP WILL FAIL WITHOUT EXPLAINING ITSELF!!! By invalid, I mean maybe you put a teamcity environment variable (like the %build.number% they show in all the examples) in that zip name that doesn't properly resolve. Or you specify a non-existent path. Or any number of things, you will see an error that says "[Octopus Deploy] Please specify a package to push". That means that one was never generated because that statement failed. I realize you want to have an auto-incrementing build number there. I'll leave it up to you to figure out how to do that.
Don't get all confused by what is running here. Octopus tries to explain it on their site, but it is hidden here. There is octo pack and octo push. The new version of octo pack is running out of sight, based on whatever statement you put in that "Package paths" box. Don't get sidetracked trying to create a nuspec package, or trying to use dotnet pack. These are dead ends for our purposes. Create a .zip file and move on with your life. Finally, notice the additional command line arguments I added. These help you out a tiny bit. They aren't required. Good luck.
We (the ASP.NET team) use TeamCity as the build server. Each repo has a build.cmd file, similar to this one. TeamCity simply invokes that file.
For Mac/Linux builds, there is a build.sh file.
At the moment you can try to use TeamCity plugin for .NET Core projects:
https://github.com/JetBrains/teamcity-dotnet-plugin
Please check these blog posts;
http://blog.coderinserepeat.com/2015/01/25/building-asp-net-5-projects-in-teamcity/
http://blog.maartenballiauw.be/post/2014/12/19/Building-future-NET-projects-is-quite-pleasant.aspx
Since there has been many changes to the ASP.NET Core world and I got asked about it a few times, I wrote down a step-by-step guide on how to setup a CI/CD environment using TeamCity for .NET Core. I think it is especially helpful for beginners.

RazorJS - Could not load type 'System.Web.Razor.Parser.MarkupParser'

When I try to use #Html.RazorJSInline() function I get
Could not load type 'System.Web.Razor.Parser.MarkupParser'
When I try to use #Html.RazorJSInclude() RazorJs is generating path to JS file but then I get the same error when trying to open the file with browser.
edit
I think it is caused by that the RazorJS was designed for Razor 1...
Does anybody find out some nice workaround?
Got here a bit late, but I hit a similar problem when trying to call RazorEngine's Razor.Parse(). I also got this message:
Could not load type 'System.Web.Razor.Parser.MarkupParser'
I was at the time using RazorEngine version 3.0.8. This issue was apparently resolved in a later version of RazorEngine (3.1.0)
So upgrading the package to this version fixed it for me.
I used the following command in the NuGet Package Manager Console to upgrade to the fixed version:
PM> Update-Package RazorEngine -Version 3.1.0
At the moment, RazorEngine is already a bunch of versions further (I think currently 3.7.2) but upgrading all the way to this version wasn't really an option for us, as this would've required quite a bit of refactoring in existing code. If this isn't an issue for you, you could always try the latest version.

Installing KVM Broke Current asp.net vnext Web Project

I installed the KVM using command line and my web project in VS2015 preview broke not compiling, but if add a new web project all works fine, how do uninstall the KVM so I can get my old project working. In this video Scott mention the issue but no solution, please see link, the video mention the issue at the 8:00 minute
video
1: http://channel9.msdn.com/Series/Whats-New-with-ASPNET-5/05 I change the to use the default alias but that did not work
NuGet Settings
I believe your versions are out of sync. Check your project.json and make sure you are not using different versions. I found that when I had 1 dependency that used 3.0.0-* it upgraded to beta2 from beta1. All of my other dependencies had beta1 actually defined. (Ex: 1.0.0-beta1). If the beta2 assembly shares the same dependency as one of your assemblies using beta1 it will override the older version of the shared assembly that is being used and causes your older version to fail.
You can remove any KRE package by deleting it from c:\Users\<user>\.kre\packages\. If you want to remove KRE and KVM then remove both the .kre folder completely.
However, you don't have to remove it to use a different version. You can either use kvm use <version> or, from VS, select the target framework in the project properties.
I have similar issue and I solved it by following steps.
In NUget Package Manager I selected only one nuget.org ( Disable myget.org by unselecting it)
I goto C:\Users\<>.kre\alias directory. Here you will find default.txt and I replace default.txt value with KRE-CLR-x86.1.0.0-beta1 ( If you downloaded latest version of Kre then this file change and it create problem for VS 2015 Preview)
After this close your solution and open it again. If possible then open as Administrator.
I hope this works for you as well.