The NUnit 3 driver encountered an error while executing reflected code
See original GitHub issueI have a simple test project that contains only one test and this test is working fine on my local machine. But when i am running same test on VSTS it’s failing with following error
2018-06-20T06:20:28.6073672Z Exception NUnit.Engine.NUnitEngineException, Exception thrown executing tests in C:\bawd\1\r25\a\PSWOR\IntegrationTests\PSWOR.Common.dll
2018-06-20T06:20:28.6073672Z The NUnit 3 driver encountered an error while executing reflected code.
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Drivers.NUnit3FrameworkDriver.CreateObject(String typeName, Object[] args)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.TestDomainRunner.LoadPackage()
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.Explore(TestFilter filter)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
2018-06-20T06:20:28.6073672Z at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, TestFilter filter)
2018-06-20T06:20:28.6073672Z Innerexception: System.Security.VerificationException: Operation could destabilize the runtime.
2018-06-20T06:20:28.6073672Z at NUnit.Framework.Api.FrameworkController..ctor(String assemblyNameOrPath, String idPrefix, IDictionary settings) in C:\src\nunit\nunit\src\NUnitFramework\framework\Api\FrameworkController.cs:line 68
2018-06-20T06:20:28.6542427Z NUnit Adapter 3.10.0.21: Test execution complete
HERE are complete VSTS logs
2018-06-20T06:20:22.7165663Z ##[section]Starting: VsTest - testAssemblies
2018-06-20T06:20:22.7165663Z ==============================================================================
2018-06-20T06:20:22.7165663Z Task : Visual Studio Test
2018-06-20T06:20:22.7165663Z Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test runner. Test frameworks that have a Visual Studio test adapter such as xUnit, NUnit, Chutzpah, etc. can also be run. Tests can be distributed on multiple agents using this task (version 2).
2018-06-20T06:20:22.7165663Z Version : 2.136.5
2018-06-20T06:20:22.7165663Z Author : Microsoft Corporation
2018-06-20T06:20:22.7165663Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=835764)
2018-06-20T06:20:22.7165663Z ==============================================================================
2018-06-20T06:20:23.2165865Z Run the tests locally using vstest.console.exe
2018-06-20T06:20:23.2165865Z ========================================================
2018-06-20T06:20:23.2165865Z Test selector : Test assemblies
2018-06-20T06:20:23.2165865Z Test assemblies : PSWOR.Common.dll
2018-06-20T06:20:23.2165865Z Test filter criteria : null
2018-06-20T06:20:23.2322089Z Search folder : C:\bawd\1\r25\a\PSWOR\IntegrationTests
2018-06-20T06:20:23.2322089Z Run settings file : C:\bawd\1\r25\a
2018-06-20T06:20:23.2322089Z Run in parallel : false
2018-06-20T06:20:23.2322089Z Run in isolation : false
2018-06-20T06:20:23.2322089Z Path to custom adapters : null
2018-06-20T06:20:23.2322089Z Other console options : null
2018-06-20T06:20:23.2322089Z Code coverage enabled : true
2018-06-20T06:20:23.2322089Z Rerun failed tests: false
2018-06-20T06:20:23.5759752Z VisualStudio version selected for test execution : toolsInstaller
2018-06-20T06:20:23.6384824Z ========================================================
2018-06-20T06:20:23.7322208Z [command]C:\bawd\1\_tool\VsTest\15.8.0-preview-20180610-02\x64\tools\net451\Common7\IDE\Extensions\TestPlatform\vstest.console.exe @C:\bawd\1\_temp\03e68761-7452-11e8-8d6b-c350225d9e87.txt
2018-06-20T06:20:23.7947760Z Microsoft (R) Test Execution Command Line Tool Version 15.8.0-preview-20180610-02
2018-06-20T06:20:23.7947760Z Copyright (c) Microsoft Corporation. All rights reserved.
2018-06-20T06:20:23.7947760Z
2018-06-20T06:20:23.7947760Z vstest.console.exe
2018-06-20T06:20:23.7947760Z "C:\bawd\1\r25\a\PSWOR\IntegrationTests\PSWOR.Common.dll"
2018-06-20T06:20:23.7947760Z /Settings:"C:\bawd\1\_temp\03ed8c40-7452-11e8-8d6b-c350225d9e87.runsettings"
2018-06-20T06:20:23.7947760Z /logger:"trx"
2018-06-20T06:20:23.7947760Z /TestAdapterPath:"C:\bawd\1\r25\a\PSWOR\IntegrationTests"
2018-06-20T06:20:24.0447349Z Starting test execution, please wait...
2018-06-20T06:20:24.7322590Z 2018-06-20T06:20:27.3573286Z NUnit Adapter 3.10.0.21: Test execution started
2018-06-20T06:20:27.3573286Z Running all tests in C:\bawd\1\r25\a\PSWOR\IntegrationTests\PSWOR.Common.dll
2018-06-20T06:20:28.6073672Z Exception NUnit.Engine.NUnitEngineException, Exception thrown executing tests in C:\bawd\1\r25\a\PSWOR\IntegrationTests\PSWOR.Common.dll
2018-06-20T06:20:28.6073672Z The NUnit 3 driver encountered an error while executing reflected code.
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Drivers.NUnit3FrameworkDriver.CreateObject(String typeName, Object[] args)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.TestDomainRunner.LoadPackage()
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.DirectTestRunner.Explore(TestFilter filter)
2018-06-20T06:20:28.6073672Z at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
2018-06-20T06:20:28.6073672Z at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, TestFilter filter)
2018-06-20T06:20:28.6073672Z Innerexception: System.Security.VerificationException: Operation could destabilize the runtime.
2018-06-20T06:20:28.6073672Z at NUnit.Framework.Api.FrameworkController..ctor(String assemblyNameOrPath, String idPrefix, IDictionary settings) in C:\src\nunit\nunit\src\NUnitFramework\framework\Api\FrameworkController.cs:line 68
2018-06-20T06:20:28.6542427Z NUnit Adapter 3.10.0.21: Test execution complete
2018-06-20T06:20:28.7636226Z No test is available in C:\bawd\1\r25\a\PSWOR\IntegrationTests\PSWOR.Common.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Here is my relese pipline tasks settings

i am using this package file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeCoverage" version="1.0.3" targetFramework="net452" />
<package id="Microsoft.NET.Test.Sdk" version="15.7.2" targetFramework="net452" />
<package id="MSTest.TestAdapter" version="1.2.1" targetFramework="net452" />
<package id="MSTest.TestFramework" version="1.2.1" targetFramework="net452" />
<package id="NUnit" version="3.10.1" targetFramework="net452" />
<package id="NUnit.ConsoleRunner" version="3.8.0" targetFramework="net452" />
<package id="NUnit.Extension.NUnitProjectLoader" version="3.5.0" targetFramework="net452" />
<package id="NUnit.Extension.NUnitV2Driver" version="3.6.0" targetFramework="net452" />
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.5.0" targetFramework="net452" />
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.3" targetFramework="net452" />
<package id="NUnit.Extension.VSProjectLoader" version="3.7.0" targetFramework="net452" />
<package id="NUnit.Runners" version="3.8.0" targetFramework="net452" />
<package id="NUnit3TestAdapter" version="3.10.0" targetFramework="net452" />
</packages>
Microsoft Visual Studio Enterprise 2017 Version 15.7.1 VisualStudio.15.Release/15.7.1+27703.2000 Microsoft .NET Framework Version 4.7.02558
Installed Version: Enterprise
Visual C++ 2017 00369-60000-00001-AA613 Microsoft Visual C++ 2017
Application Insights Tools for Visual Studio Package 8.12.10405.1 Application Insights Tools for Visual Studio
ASP.NET and Web Tools 2017 15.0.40501.0 ASP.NET and Web Tools 2017
ASP.NET Core Razor Language Services 15.7.31476 Provides languages services for ASP.NET Core Razor.
ASP.NET Web Frameworks and Tools 2017 5.2.60419.0 For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 15.0.40424.0 Azure App Service Tools v3.0.0
Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.
Azure Data Lake Tools for Visual Studio 2.3.3000.5 Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools 15.0.40502.0 Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio 2.3.3000.5 Microsoft Azure Stream Analytics Tools for Visual Studio
C# Tools 2.8.0-beta6-62830-08. Commit Hash: e595ee276d14e14bfb3eb323fb57f2aa668bddea C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events
JavaScript Language Service 2.0 JavaScript Language Service
Microsoft Azure HDInsight Azure Node 2.3.3000.5 HDInsight Node under Azure Node
Microsoft Azure Hive Query Language Service 2.3.3000.5 Language service for Hive query
Microsoft Azure Service Fabric Tools for Visual Studio 2.1 Microsoft Azure Service Fabric Tools for Visual Studio
Microsoft Azure Stream Analytics Language Service 2.3.3000.5 Language service for Azure Stream Analytics
Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node
Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10420.2
Microsoft Continuous Delivery Tools for Visual Studio 0.3 Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.
Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards
Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.
Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package
NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info
ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info
SQL Server Data Tools 15.1.61804.210 Microsoft SQL Server Data Tools
Test Adapter for Boost.Test 1.0 Enables Visual Studio’s testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.
Test Adapter for Google Test 1.0 Enables Visual Studio’s testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.
ToolWindowHostedEditor 1.0 Hosting json editor into a tool window
TypeScript Tools 15.7.20419.2003 TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 2.8.0-beta6-62830-08. Commit Hash: e595ee276d14e14bfb3eb323fb57f2aa668bddea Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 10.1 for F# 4.1 15.7.0.0. Commit Hash: 16ecf5a30ad868d183c58e4a71a71c23d4ed3ba9. Microsoft Visual F# Tools 10.1 for F# 4.1
Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake
Windows Machine Learning Generator Extension 1.0 Windows Machine Learning Visual Studio Extension Detailed Info
Build Dlls IntegrationTests.zip
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (3 by maintainers)

Top Related StackOverflow Question
@millsy013 I understand you got the issue, but as long as we dont get any repro project we have no way of finding out what causes this. A “normal” project behaves as it should, both locally and on VSTS.
So please, help yourself by helping us by uploading a small repro project we can use. (And please, source code, not dll’s as above)
Seems like a good workaround.