Testing ASP.NET Core full .NET Framework with TestServer gives method not found in vs 2017 - unit-testing

When trying to run test in Visual Studio 2017, all is compiling without issue,
However when I'm trying to create server and client to test:
this.Server = new TestServer(
new WebHostBuilder()
.UseStartup<Startup>()
.UseContentRoot(di.FullName));
this.Client = this.Server.CreateClient();
The TestServeris complaining about wrong dependencies (it tries to load version 1.0.0) even if TestHost package is:
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.1" />
Also test is failing with exception:
Cannot find method: 'System.Net.Http.HttpClient Microsoft.AspNetCore.TestHost.TestServer.CreateClient()'..

It is related to wrong test template in VS 2017
manually adding in the top <PropertyGroup>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
in csproj file fixes issue

Related

Team Build Nuget restore failure with .NET Core 2.0 + .Net Standard 2.0

I have a VS2017 solution that contains a .NET Core 2.0 console project that references a .NET Standard 2.0 class library, as well as a number of other NuGet packages. The solution builds fine on my development machine.
When I try to run NuGet restore on the TFS build server with NuGet 4.0.0 or 4.1.0, I get the following error:
Package (mypackagename) 1.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package (mypackagename) 1.0.0 supports:
- net35 (.NETFramework,Version=v3.5)
- netstandard2.0 (.NETStandard,Version=v2.0)
This error message is similar to that described in Nuget restore fails for ASP.NET Core 2.0 project on build server so I tried the solution suggested there, which is to use NuGet 4.3.0 or later. I've tried all released versions from 4.3.0 to 4.6.2, and this time I get the following error from NuGet restore:
2018-04-17T15:45:15.2611952Z Value cannot be null.
2018-04-17T15:45:15.2611952Z Parameter name: key
2018-04-17T15:45:15.2611952Z System.ArgumentNullException: Value cannot be null.
2018-04-17T15:45:15.2611952Z Parameter name: key
2018-04-17T15:45:15.2611952Z at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
2018-04-17T15:45:15.2611952Z at NuGet.Commands.RestoreCommandProvidersCache.GetOrCreate(String globalPackagesPath, IReadOnlyList`1 fallbackPackagesPaths, IReadOnlyList`1 sources, SourceCacheContext cacheContext, ILogger log)
2018-04-17T15:45:15.2611952Z at NuGet.Commands.DependencyGraphSpecRequestProvider.Create(String projectNameToRestore, ExternalProjectReference project, HashSet`1 projectReferenceClosure, RestoreArgs restoreArgs, DependencyGraphSpec projectDgSpec)
2018-04-17T15:45:15.2611952Z at NuGet.Commands.DependencyGraphSpecRequestProvider.GetRequestsFromItems(RestoreArgs restoreContext, DependencyGraphSpec dgFile)
2018-04-17T15:45:15.2611952Z at NuGet.Commands.DependencyGraphSpecRequestProvider.CreateRequests(RestoreArgs restoreContext)
2018-04-17T15:45:15.2611952Z at NuGet.Commands.RestoreRunner.<CreatePreLoadedRequests>d__11.MoveNext()
2018-04-17T15:45:15.2611952Z --- End of stack trace from previous location where exception was thrown ---
Any suggestions as to how I can get this working?
I fixed this by setting "Clean = True" in the "Get Sources" task of my Team Build.
After doing this, I could use a recent version of NuGet (4.6.2), which no longer throws the ArgumentNullException above.
I suspect a bug in NuGet, where it gets confused by files left around from a previous build.

Could not load file or assembly System.Reflection.TypeExtensions

I got below exception while running xunit test projects which works under VS 2017 15.3
[2017/12/4 23:08:40 Error] [xUnit.net 00:00:00.0033291] xxx.Test: Catastrophic failure: System.TypeInitializationException: The type initializer for 'Xunit.DiaSession' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at Xunit.DiaSession..cctor()
--- End of inner exception stack trace ---
at Xunit.DiaSession..ctor(String assemblyFileName)
at Xunit.DiaSessionWrapper..ctor(String assemblyFilename)
at Xunit.XunitFrontController..ctor(AppDomainSupport appDomainSupport, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink)
at Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner.RunTestsInAssembly(IRunContext runContext, IFrameworkHandle frameworkHandle, LoggerHelper logger, IMessageSinkWithTypes reporterMessageHandler, AssemblyRunInfo runInfo)
My current VS 2017 version is 15.4.5.
I have tried the work around which has been provided previously, but none did not work. And I have try to downgrade my VS 2016 to 15.3, but I could not find the 15.3 package to install. I have tried to install xunit to latest version.
Any help would be appreciated.
Update:
Project Type:xUnit Test Project(.NET Core)
Target: net 461
It seems VS 2017 fail to load specific "xunit.runner.visualstudio", after checking VS2017 15.4.2 - Unable to run tests for projects targeting .NET Framework 4.6.x #1542 again, I deleted the "%TEMP%\VisualStudioTestExplorerExtensions", create a new Xunit project, change the nonworked.csproj xunit.runner.visualstudio from 2.2.0 to 2.3.1, it works now. Not sure why it did not work when I try it previous.
Hope it will help others.
You need to install System.Reflection.TypeExtensions using VS Package Manager using the following command:
Install-Package System.Reflection.TypeExtensions -Version 4.5.1
for more information please review the following link
System.Reflection.TypeExtensions

The install of solidity extension was failed for Visual Studio 2017

I tried to install solidity extension for Visual Studio 2017, I downloaded VSIX Installer from the link bellow:
https://marketplace.visualstudio.com/items?itemName=ConsenSys.Solidity
when I tried to run the VSIX file, the installation failed immediately with the given message:
"Install Failed
The install of the extension was not successful for all the selected products. For more information, click the install log link at the bottom of the dialog.
This extension is not installable on any currently installed products."
I also tried to read the log file but it is very huge and many different things happened there. I appreciate if someone who had the same experience and fixed it could advice me how to fix it.
For anyone who is trying to install on VS 2017 just open the extract the package and then edit the extension.vsixmanifest to change the wrongly added brackets to square brackets. As below:
<InstallationTarget Version="[14.0,15.0]" Id="Microsoft.VisualStudio.Pro" />
<InstallationTarget Version="[14.0,15.0]" Id="Microsoft.VisualStudio.Community" />
<InstallationTarget Version="[14.0,15.0]" Id="Microsoft.VisualStudio.Enterprise" />
If still you face issue, With out converting to .zip file, do " Open Archive " - With in that edit the files as below
<Installation>
.... Version="[14.0,15.0]"
.... Version="[14.0,15.0]"
.... Version="[14.0,15.0]"
</Installation>
<Dependencies>
.... Version="[4.5,]"
</Dependencies>
save the file and run as it. ( Here there is no conversion from vsix to zip and back - edit is direct on the vsix ) - Installation is success for me.
The page says "Works with Visual Studio 2015".

nuget restore failing in team services build

I have 2 local assemblies referenced via nuget (packed the dll's up) using vs2017 on a asp.net core solution, builds fine locally.
Now trying to generate a build via VSTS i am getting the following error,
Detected NuGet version 4.0.0.2283 / 4.0.0
SYSTEMVSSCONNECTION exists true
Saving NuGet.config to a temporary config file.
d:\a\_tool\NuGet\4.0.0\x64\nuget.exe restore d:\a\1\s\TestFrameworkCoreAPI.sln -Verbosity Detailed -NonInteractive -ConfigFile d:\a\1\Nuget\tempNuGet_37.config
NuGet Version: 4.0.0.2283
MSBuild auto-detection: using msbuild version '15.3.409.57025' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
MSBuild P2P timeout [ms]: 120000
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\msbuild.exe /t:GenerateRestoreGraphFile /nologo /nr:false /p:RestoreUseCustomAfterTargets=true /p:BuildProjectReferences=false /v:q /p:NuGetRestoreTargets="d:\a\_temp\NuGet-Scratch\w53qa5rr.4sd.targets" /p:RestoreTaskAssemblyFile="d:\a\_tool\NuGet\4.0.0\x64\nuget.exe" /p:RestoreGraphOutputPath="d:\a\_temp\NuGet-Scratch\4mlmlfgh.mmy.result" /p:ExcludeRestorePackageImports=true /p:RestoreRecursive=False /p:RestoreProjectFilterMode=exclusionlist /p:RestoreContinueOnError=WarnAndContinue /p:RestoreGraphProjectInput="d:\a\1\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj;" "d:\a\_temp\NuGet-Scratch\w53qa5rr.4sd.targets"
Running restore with 2 concurrent jobs.
Reading project file d:\a\1\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj.
Reading project file d:\a\1\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj.
Restoring packages for d:\a\1\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj...
Restoring packages for d:\a\1\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj...
Restoring packages for .NETCoreApp,Version=v1.1...
Restoring packages for .NETCoreApp,Version=v2.0...
System.AggregateException: One or more errors occurred. ---> NuGet.Protocol.Core.Types.FatalProtocolException: Failed to retrieve information about 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' from remote source 'D:\TestFrameworkAssemblies'.
at NuGet.Protocol.LocalV3FindPackageByIdResource.GetVersionsCore(String id, ILogger logger)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at NuGet.Protocol.LocalV3FindPackageByIdResource.GetAllVersionsAsync(String id, SourceCacheContext cacheContext, ILogger logger, CancellationToken token)
at NuGet.Commands.SourceRepositoryDependencyProvider.<FindLibraryAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
Error: d:\a\_tool\NuGet\4.0.0\x64\nuget.exe failed with return code: 1
Packages failed to restore
I have a nuget.config file in a .nuget folder located in the root of solution,
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- remove any machine-wide sources with <clear/> -->
<clear />
<add key="Test Framework" value="D:\TestFrameworkAssemblies" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
This is what is in the VSTS build def, NuGet restore step
It looks like it always references my local assembly and not the standard nuget.org, now in the config file, if i take out my local entry to framework assemblies, the nuget part works but i get a primary reference error as it cannot find the 2 assemblies i have packed locally.
Been going round in circles with this at the moment, how can you get VSTS to restore local packed assemblies as well as from nuget.org. I am using Hosted 2017 as well.
thanks in advance
It seems you were queue the build on Hosted agent. Since there has the packages located on your local machine, you should build with the private agent which located on your local machine.
Additional, if you need to queue the build on Hosted agent, you should add the local packages in repository, and then reference the packages with the new path and change the value in nuget.config.

Xamarin linker error with AWSSDK

I have a Xamarin forms mobile project (Android and iOS).
When I try to install the AWSSDK.S3 to access Amazon services, I get the following linker error when trying to build iOS:
Failed to resolve "System.Void Amazon.Runtime.Internal.Util.AESEncryptionPutObjectStream::.ctor(System.IO.Stream,System.Byte[],System.Byte[])" reference from "AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604"
..Android build has a similar error.
I have the following libraries installed:
AWSSDK.S3 v3.1.1.1
AWSSDK.Core v3.3.4
AWSSDK.SecurityToken v3.3.0.2
AWSSDK.CognitolIdenity v3.3.0.2
AWSSDK.CognitoIdentityProvider v3.3.1.2
PCLCrypto v2.0.147
PCLStorage v1.0.2
the only code in my project is:
var amazonClient = new AmazonS3Client();
Any ideas?
possible (bad) workaround that seems to work:
change in Linker Options/Linker behavior:
to: Don't link
instead of: Link SDK Assemblies only
The answer turns out to be found here:
Xamarin Forms IOS Failed to load assembly System.Net.Http.Primitive
even though its a different assembly error, the fix is the same:
update all the AWS.Core to the latest version: v3.3.6 in my case
install Microsoft.Bcl.Build v1.0.21
install Microsoft.Net.Http v2.2.29
Rolling back to AWSSDK.S3 V3.1.10 worked for me, done using the NuGet manager in Visual Studio. =)