I have a .NET application using .NET Framework 4.7 that includes the xUnit unit testing framework.
The application and unit test execute as expected from my local dev environment and from Azure using a .net solution build.
I recently added another build based on a yml file to Azure that is building the same code and executing the same unit tests,
however, the number of unit tests being executed with the yml configuration are vastly different and nearly half of the unit test are not executed when using the yml configuration. The yml file is super simple that is the first place I started my troubleshooting efforts and will be glad to share if needed.
Review of the test results between the solution build versus the yml build indicated the following warning that is only in the yml unit test results:
Warning 5/14/2020 1:46:33 PM [MSTest][Discovery][d:\a\1\s\src\OTEMS\packages\MSTest.TestAdapter.2.1.0\build\netcoreapp1.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll] Unable to load types from the test source 'd:\a\1\s\src\OTEMS\packages\MSTest.TestAdapter.2.1.0\build\netcoreapp1.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll'. Some or all of the tests in this source may not be discovered.
Error: System.TypeLoadException: Method 'get_DataRow' in type 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation' from assembly 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' does not have an implementation.
Note the \netcoreapp1.0\ in the path. This warning only occurs with the yml variation but the project is NOT a .net core build, and I can't seem to find where this is being referenced or if it is the actual problem.
Related
Currently, we are using .Net Core 2.1 Framework for our test automation Web API Project.
I am trying to run one of the test project dlls for test cases execution.
Please find below the command through Visual Studio IDE
Command : dotnet test APItests.dll,
The above command works well on my local machine with Visual Studio, test cases are getting executed.
I have built the Azure Build pipeline as well as the release pipeline for the same.
Also artifacts are getting published to drop location.
But in the release pipeline .Net core test task is failing with the below error.
Framework: .Net Core 2.1
Error:
An assembly specified in the application dependencies manifest (APItests.deps.json) was not found:
package: ‘Microsoft.AspNet.WebApi.Client’, version: ‘5.2.6’
path: ‘lib/netstandard2.0/System.Net.Http.Formatting.dll’
Could you please find the YAML file details below.
Steps:
task: DotNetCoreCLI#2
displayName ‘dotnet custom’
inputs:
command: custom
projects: ‘\TestAutomation.Application.Hosting.WebApi\ApiTests.dll’
custom: vstest
workingDirectory: ‘$(System.DefaultWorkingDirectory)’
Could you please have a look once and let me know the suggested solution for the same.
To resolve this An assembly specified in the application dependencies manifest (APItests.deps.json) was not found: package: ‘Microsoft.AspNet.WebApi.Client’, version: ‘5.2.6’ path: ‘lib/netstandard2.0/System.Net.Http.Formatting.dll’ error, try either of the following ways:
(Thank you Jirapong. Posting your suggestion as an answer to help other community members.)
You can try upgrading all project dependencies or modifying the installer to include the new files.
If the migration is a class library in Azure Functions project then you have to make sure when you run Add-Migration while the EF Library project is selected as Startup Project.
You can refer to An assembly specified in the application dependencies manifest (appname.deps.json) was not found: package, An assembly specified in the application dependencies manifest (...) was not found and Fixing “An assembly specified in the application dependencies manifest projectname.deps.json was not found”
Last week I upgraded my .NET Core Web API from 2.2 to 3.0.
I had a lot of issues with packages and still struggling.
Case 1: What I have right now is that all of my tests are failing:
unit tests, integrations tests, etc.
I'm using:
Nunit (3.12.0)
NUnit3TestAdapter (3.15.1)
Moq 4.13.0
Microsoft.NET.Test.sdk (16.2.0)
Microsoft.AspNetCore.Mvc.Testing
When I start debugging my tests I get the following error message:
System.IO.FileNotFoundException HResult=0x80070002
Message=Could not load file or assembly 'Microsoft.IntelliTrace.Core, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Source=System.Private.CoreLib.
The error occurred in the RuntimeAssembly file (part of system.private.corelib), method InternalLoadAssemblyName.
When I continue I get this:
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.IntelliTrace.Core, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'
Case 2: When I'm not debugging my tests but just run my application en startup swagger, I can use every call but my output window is filled with thousands of Exceptions like thrown:
'System.InvalidCastException' in Swashbuckle.AspNetCore.SwaggerGen.dll
This happens when the Linq class Where.SpeedOpt.cs is used and the List.cs class of generic, also in System.Private.CoreLib.
Are case 1 and case 2 related to each other?
Anyone have a workaround or solution?
Case 1 also fixed:
When using .Net Core 3.0 and automapper
you should add automapper with additional parameter
services.AddAutoMapper(typeof(Startup));
In .Net core 2.2 i just had
services.AddAutoMapper();
He fails on this during unit and integrationtesting
not on normal startup
Case 2 (swagger error) is solved.
Seems there was a bug in the swagger 5.0.0 packages
That bug is solved in the 5.0.0-rc4 version
Case 1 is still open.
I tried to reproduce with different coding and see what the results are.
When i instantiate a new httpclient, there is no error.
Nevertheless, i can not call my api because it's secured and i get the "unathorized" error (normal behaviour)
When i instantiate a new httpclient with my webapplicationfactory, there is the error.
Is there something that is not initialized from startup when i run my tests
instead of running the core api thru normal startup and calling swagger?
Maybe a problem in startup that is only an issue in unit and integrationtests?
Regards
GSharp
I keep getting this error:
System.IO.FileNotFoundException: System.IO.FileNotFoundException: Could not load file or assembly 'Moq, Version=4.2.1507.118, Culture=neutral, PublicKeyToken=69f491c39445e920' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF.
It compiles fine in my project, and all of my Moq Nuget packages are set to version 4.2.1507.118. I don't have any binding redirects for Moq.
By the way, is there any way to turn assembly binding logging on for a VSTS hosted agent?
Log files:
Here's my build step log output
Here's my test step log output
After updating an assembly, my xUnit tests fail to run.
My project was using System.Web.Http version 5.2.3. I replaced this using Nuget with a fork of System.Web.Http version 5.2.4. Inspecting the reference shows the correct path to the new DLL.
When I run xUnit, it discovers the tests, but gives me the following warning:
[11/04/2018 10:43:30 AM Warning] [xUnit.net 00:00:00.9421698] Skipping: API.IntegrationTests (could not find dependent assembly 'System.Web.Http, Version=5.2.4')
It then skips all tests.
I'm at a loss. Any help is very appreciated.
TL;DR: Is it possible to use mixed-mode assemblies in Azure Functions?
Details: I have an in-house mixed-mode assembly that I'm trying to use in an Azure Function. When I try to build, I get the following error:
------ Build started: Project: AzureDemo, Configuration: Debug x64 ------
AzureDemo -> C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll
C:\Users\hugh\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'file:///C:\src\local\2017\AzureDemo\bin\x64\Debug\net462\bin\AzureDemo.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Done building project "AzureDemo.csproj" -- FAILED.
For clarity, the in-house library is x64 and my demo project is also x64, so it's not an x86/x64 problem.
Also, when I take the code out of the Azure Function project and put it in a plain old .NET Core 2.0 project, it builds just fine. edit: it builds fine, but it still doesn't run (System.EntryPointNotFoundException: A library name must be specified in a DllImport attribute applied to non-IJW methods.). So I may be in deeper water than I thought.
I'm kind of afraid Azure Functions won't work with mixed-mode assemblies... but I haven't found any definitive statement to that effect.
I'm also a little concerned that the fact that it's using netstandard1.0 might have something to do with it.
The error is happening at build time when the SDK launches the build task to generate the build artifacts/function metadata.
I've opened this issue with the details to track the bug: https://github.com/Azure/azure-functions-vs-build-sdk/issues/131
Actual x64 CLI releases would also be required for successful local testing, and this is tracked here: https://github.com/Azure/azure-functions-cli/issues/117