How to run NUnit 3.0 with Mono 4.0 runtime? - mono

I'm trying to run a test assembly built with .NET Framework 4.5.1 on Mono 4.0 and NUnit 3.0 on Windows.
Does anyone know how to make nunit-console.exe see the Mono 4.0 runtime that is installed on my machine and stop saying it is unknown or not available?
If I run nunit-console.exe through mono and set the target framework:
mono C:\Program Files (x86)\NUnit.org\bin\nunit-console.exe --framework=mono-4.0 "C:\MyTestAssembly.dll"
NUnit Console Runner 3.0.5610
Copyright (C) 2014 Charlie Poole
Test Files
C:\MyTestAssembly.dll
Runtime Environment
OS Version: Microsoft Windows NT 6.3.9600.0
CLR Version: 4.0.30319.0
Options
ProcessModel: Default DomainUsage: Default
Execution Runtime: mono-4.0
Work Directory: C:\
Internal Trace: Off
The requested framework mono-4.0 is unknown or not available.
If I run nunit-console.exe directly, without mono, the output is the same:
C:\Program Files (x86)\NUnit.org\bin\nunit-console.exe --framework=mono-4.0 "C:\MyTestAssembly.dll"
If I run nunit-console.exe through mono but without the target framework, the output changes:
mono C:\Program Files (x86)\NUnit.org\bin\nunit-console.exe "C:\MyTestAssembly.dll"
NUnit Console Runner 3.0.5610
Copyright (C) 2014 Charlie Poole
Test Files
C:\MyTestAssembly.dll
Runtime Environment
OS Version: Microsoft Windows NT 6.3.9600.0
CLR Version: 4.0.30319.0
Options
ProcessModel: Default DomainUsage: Default
Execution Runtime: Not Specified
Work Directory: H:\Safe\Desenvolvimento\Concert\Reactive Services
Internal Trace: Off
System.ArgumentException: The mono-4.0 framework is not available
Parameter name: framework
at NUnit.Engine.Services.TestAgency.LaunchAgentProcess (NUnit.Engine.TestPackage package) [0x00000] in :0
at NUnit.Engine.Services.TestAgency.CreateRemoteAgent (NUnit.Engine.TestPackage package, Int32 waitTime) [0x00000] in
:0
at NUnit.Engine.Services.TestAgency.GetAgent (NUnit.Engine.TestPackage package, Int32 waitTime) [0x00000] in :0
at (wrapper remoting-invoke-with-check) NUnit.Engine.Services.TestAgency:GetAgent (NUnit.Engine.TestPackage,int)
at NUnit.Engine.Runners.ProcessRunner.LoadPackage () [0x00000] in :0
And finally, if I run the last option using NUnit 2.6.4, the test runs but the mono process hangs at the end.
mono C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe "C:\MyTestAssembly.dll"
And if I run without mono and the target framework using NUnit 2.6.4 or NUnit 3.0, the test runs and the process ends normally.
C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe "C:\MyTestAssembly.dll"
C:\Program Files (x86)\NUnit.org\bin\nunit-console.exe "C:\MyTestAssembly.dll"

You have to use NUnit embedded in Mono. Execute the following commands in console:
cd C:\Program Files (x86)\Mono\bin
nunit-console4 *PATH TO YOUR .Tests.dll*

Related

Visual Studio for Mac won't start after updating to version 7.5.3 - Assemblies not properly installed in the GAC

I updated Visual studio for mac from beta channel to latest stable channel and now it does't start anymore.
I reinstalled it and still doesn't start.
Here is a portion of the logs:
INFO [2018-07-04 00:16:23Z]: Starting Visual Studio 2017 for Mac 7.5.3 (build 7)
INFO [2018-07-04 00:16:23Z]: Running on Mono 5.10.1.57 (2017-12/ea8a24b1bbf) (64-bit)
INFO [2018-07-04 00:16:23Z]: Operating System: Mac OS X 10.13.5
Darwin 17.6.0 Darwin Kernel Version 17.6.0
Tue May 8 15:22:16 PDT 2018
root:xnu-4570.61.1~1/RELEASE_X86_64 x86_64
INFO [2018-07-04 00:16:23Z]: GTK: Using gtkrc from /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/gtkrc.mac
Could not find `Microsoft.Build.Framework` referenced by assembly `MonoDevelop.Core, Version=2.6.0.0, Culture=neutral, PublicKeyToken=3ead7498f347467b`.
...
Starting Visual Studio
FATAL ERROR [2018-07-04 00:16:30Z]: Visual Studio failed to start. Some of the assemblies required to run Visual Studio (for example gtk-sharp)may not be properly installed in the GAC.
System.InvalidOperationException: Extension node not found in path: /MonoDevelop/Core/PlatformService
at Mono.Addins.ExtensionContext.GetExtensionObjects (System.String path, System.Type arrayElementType, System.Boolean reuseCachedInstance) [0x0001c] in /Users/builder/data/lanes/5965/13cecd02/source/monodevelop/main/external/mono-addins/Mono.Addins/Mono.Addins/ExtensionContext.cs:670
at Mono.Addins.ExtensionContext.GetExtensionObjects (System.String path) [0x00000] in /Users/builder/data/lanes/5965/13cecd02/source/monodevelop/main/external/mono-addins/Mono.Addins/Mono.Addins/ExtensionContext.cs:534
at Mono.Addins.AddinManager.GetExtensionObjects (System.String path) [0x0000a] in /Users/builder/data/lanes/5965/13cecd02/source/monodevelop/main/external/mono-addins/Mono.Addins/Mono.Addins/AddinManager.cs:554
at MonoDevelop.Ide.DesktopService.Initialize () [0x00008] in /Users/builder/data/lanes/5965/13cecd02/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/DesktopService.cs:57
at MonoDevelop.Ide.IdeStartup.Run (MonoDevelop.Ide.MonoDevelopOptions options) [0x0030b] in /Users/builder/data/lanes/5965/13cecd02/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs:178
at MonoDevelop.Ide.IdeStartup.Main (System.String[] args, MonoDevelop.Ide.Extensions.IdeCustomizer customizer) [0x0008f] in /Users/builder/data/lanes/5965/13cecd02/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs:627
It seems I encountered a known issue. A workaround is described here and it worked for me. It says to delete that folder: ~/Library/Caches/VisualStudio/7.0/addin-db-002/

Dotnet core web project in Raspberry Pi

I have installed dotnet core on my Raspberry PI running Ubuntu Server 16.04 as per https://github.com/dotnet/core/blob/RaspberryPi/samples/ARMInstructions.md
I create and publish dotnet core project on Linux Mint 18 running dotnet core version 1.0.0-preview2-1-003177. (Also modifying runtimeconfig.json file to update the version to 1.2.0-beta-001206-00).
I then copy the published application into the Raspberry pi and run the dll.
For console application it works fine.
But when I repeat the steps for a web project and run it I get below error
Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'System.ComponentModel.Primitives, Version=4.2.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located
assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040) at
Microsoft.Extensions.FileProviders.PhysicalFileProvider.CreateFileWatcher(String
root) at
Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment
hostingEnvironment, String applicationName, String contentRootPath,
WebHostOptions options) at
Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at
WebApplication.Program.Main(String[] args) in
/home/Development/aspCoreDemo3/Program.cs:line 14 Aborted
Check out the changes you need to make in the project.json.
https://github.com/dotnet/coreclr/issues/9168

VSTS Build fails running NUnit tests

When building a visual studio solution using visual studio team services it runs the unit tests, written in nunit 3 using the nunit 3 NUnit3TestAdapter it starts running the tests.
The error it gives is: Error: Illegal characters in path.
The complete output as follows
2016-02-11T17:02:40.8514411Z Executing the powershell script: C:\BuildAgent\tasks\VSTest\1.0.29\VSTest.ps1
2016-02-11T17:02:41.1483135Z ##[debug]Calling Invoke-VSTest for all test assemblies
2016-02-11T17:02:41.2108131Z Working folder: C:\BuildAgent\_work\5
2016-02-11T17:02:41.2108131Z Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\BuildAgent\_work\5\s\xxxxxxxxxxTests\bin\Release\xxxxxxxxxxTests.dll" /logger:trx /TestAdapterPath:"C:\BuildAgent\_work\5\s"
2016-02-11T17:02:41.5240692Z Microsoft (R) Test Execution Command Line Tool Version 14.0.24720.0
2016-02-11T17:02:41.5240692Z Copyright (c) Microsoft Corporation. All rights reserved.
2016-02-11T17:02:42.1326930Z Starting test execution, please wait...
2016-02-11T17:02:46.4921857Z Information: NUnit Adapter 3.0.8.0 executing tests is started
2016-02-11T17:02:46.5077303Z Information: Running all tests in C:\BuildAgent\_work\5\s\xxxxxxxxxxTests\bin\Release\xxxxxxxxxxTests.dll
2016-02-11T17:02:46.6327336Z Information: NUnit Adapter 3.0.8.0 executing tests is finished
2016-02-11T17:02:46.6327336Z ##[error]Error: Exception System.ArgumentException, Exception thrown executing tests
2016-02-11T17:02:46.6327336Z ##[error]
2016-02-11T17:02:46.6327336Z ##[error]Error: Illegal characters in path.
2016-02-11T17:02:46.6327336Z ##[error]
2016-02-11T17:02:46.7108474Z Information: Additionally, you can try specifying '/UseVsixExtensions' command if the test discoverer & executor is installed on the machine as vsix extensions and your installation supports vsix extensions. Example: vstest.console.exe myTests.dll /UseVsixExtensions:true
2016-02-11T17:02:46.8358887Z ##[error]VSTest Test Run failed with exit code: 1
2016-02-11T17:02:46.8514965Z ##[warning]No results found to publish.
We have an on premise build agent but I don't think this should make an difference.
Any advice you can give it appreciated.
FWIW, I switched on verbose logging by following the Tips and Tricks and got this:
2016-02-23T14:45:49.5620657Z Information: Running all tests in C:\TFS2015\_work\3\s\BlaBlaTests\bin\Debug\BlaBlaTests.dll
2016-02-23T14:45:49.6088663Z ##[error]Error: Exception thrown executing tests
2016-02-23T14:45:49.6088663Z ##[error]
2016-02-23T14:45:49.6088663Z ##[error]Error: System.ArgumentException: Illegal characters in path.
2016-02-23T14:45:49.6088663Z ##[error] at System.IO.Path.CheckInvalidPathChars(String path)
2016-02-23T14:45:49.6088663Z ##[error] at System.IO.Path.Combine(String path1, String path2)
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.Engine.Services.ExtensionService.ProcessAddinsFile(DirectoryInfo baseDir, String fileName)
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.Engine.Services.ExtensionService.FindExtensionsInDirectory(DirectoryInfo startDir)
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.Engine.Services.ExtensionService.StartService()
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.Engine.Services.ServiceManager.StartServices()
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.Engine.TestEngine.Initialize()
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.Engine.TestEngine.GetRunner(TestPackage package)
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.VisualStudio.TestAdapter.NUnitTestAdapter.GetRunnerFor(String assemblyName)
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyName, IFrameworkHandle frameworkHandle)
2016-02-23T14:45:49.6088663Z ##[error] at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
2016-02-23T14:45:49.6088663Z ##[error]
2016-02-23T14:45:49.6088663Z Information: NUnit Adapter 3.0.8.0 executing tests is finished
which correlates with %LOCALAPPDATA%\NUnit\Nunit30Settings.xml being accessed but might not be related. ExtensionService is here.
Issues #117 and #118 are related to this with a fix as provided by RobertK66:
If you install the Version 3.0.8.0 as a Nuget package then there is a
corrupted (not empty!) “ignore.addins” file installed in the
packages\NUnit3TestAdapter.3.0.8-ctp-8\lib folder. Earlier Versions
did install a 0byte empty file!
After removing the content of this file in the
/packages/NUnit3TestAdapter.3.0.8-ctp-8\lib folder and
deleting the cached version of the adapter under
\AppData\Local\Temp\VisualStudioTestExplorerExtensions...
everything works as expected!
I met this issue when I use NUnit3 Test Adapter Nuget Package during the build. And I resolved it by installing NUnit3 Test Adapter and upload all the installed files to Version Control and use it as the Test Adapter.
Since you are using on premise build agent. You can easily install the NUnit3 Test Adapter on the build agent and use "/UseVsixExtensions:true" argument as the error message indicates.

.Net/Mono & Ubuntu versus log4net

I've been asked to write a small instrument-calibration app on Ubuntu Linux (14.04) and have been writing some small proof-of-concept apps (serial i/o, GUI, SQLite, etc.) to see if Mono is a good fit. Things were going well until I tested log4net, my favorite logging package. I cannot get the code to work. Here's a simple test app that works fine on a Windows box:
using System;
using log4net;
using log4net.Config;
public class L
{
public static void Main(string[] args)
{
Console.WriteLine("Version: " + Environment.Version);
XmlConfigurator.Configure(
new System.IO.FileInfo("console.logconfig.xml"));
Console.WriteLine("logging configured.");
ILog log = LogManager.GetLogger("root");
log.Info("This is an info message.");
log.Warn("This is a warning message.");
log.Error("This is an error message.");
}
}
Compiled with
gmcs -pkg:log4net,dotnet -main:L -out:L.exe L.cs
the code compiles, but generates a runtime error:
Version: 2.0.50727.1433
Missing method System.Reflection.Assembly::op_Equality(Assembly,Assembly) in assembly /usr/lib/mono/2.0/mscorlib.dll, referenced in assembly /usr/lib/mono/gac/log4net/1.2.10.0__a5715cc6d5c3540b/log4net.dll
Unhandled Exception:
System.MissingMethodException: Method not found: 'System.Reflection.Assembly.op_Equality'.
at log4net.LogManager.GetRepository (System.Reflection.Assembly repositoryAssembly) [0x00000] in <filename unknown>:0
at log4net.Config.XmlConfigurator.Configure (System.IO.FileInfo configFile) [0x00000] in <filename unknown>:0
at L.Main (System.String[] args) [0x00000] in <filename unknown>:0
This looks like a .Net version mismatch (maybe op_equality wasn't available in .Net 2.0?). When I try to force version 4 or 4.5 of the SDK:
gmcs -sdk:4.5 -pkg:log4n35,dotnet -main:L -out:L.exe L.cs
I get a compile error:
error CS0006: Metadata file `cscompmgd.dll' could not be found
This is on a brand-new Ubuntu 14.04 VM with Mono installed via:
sudo apt-get install mono-complete
sudo apt-get install liblog4net1.2-cil
sudo apt-get install liblog4net-cil-dev
Recommendations, please?
Unfortunately the version of log4net packaged for Ubuntu (1.2.10) is pretty old and known to have problems with .NET 4.0. 1.2.11 has been released in October 2011 and as of this writing 1.2.13 is the latest release.
You need to download the latest version from the Apache log4net site directly: http://logging.apache.org/log4net/download_log4net.cgi
You almost had it; Ubuntu 14.04:
gmcs -sdk:4.5 -r:/usr/lib/cli/log4net-1.2/log4net.dll App.cs

Issues with running nunit-console.exe with Mono

I could make a dll for NUnit NUnit test under mono, but when I tried to run in with nunit-console.exe I get the following error message.
Runtime Environment -
OS Version: Unix 10.3.0.0
CLR Version: 2.0.50727.1433 ( 2.6.4 (tarball Thu Apr 22 13:24:33 MDT 2010) )
ProcessModel: Default DomainUsage: Single
Execution Runtime: mono-2.0
** (/Users/smcho/bin/NUnit-2.5.5.10112/bin/net-2.0/nunit-console.exe:36800): WARNING **: The following assembly referenced from /private/var/folders/m4/m4u1hmP+FHOQaiZbHj1UCk+++TI/-Tmp-/nunit20/ShadowCopyCache/36800_634111616836311880/Tests_-22323139/assembly/shadow/54274fc2/118e035c_45a94c9e_00000001/mut.dll could not be loaded:
Assembly: nunit.framework (assemblyref_index=1)
Version: 2.5.5.10112
Public Key: 96d09a1eb7f44a77
System error: Invalid argument
** (/Users/smcho/bin/NUnit-2.5.5.10112/bin/net-2.0/nunit-console.exe:36800): WARNING **: Could not load file or assembly 'nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies.
What might be wrong? I have nunit.framework.dll under /Users/smcho/bin/NUnit-2.5.5.10112/bin/net-2.0/framework, but it doesn't seem to know about this.
This is another frustrating point about using NUnit in Mono. As far as I've been able to tell, you need to have all of those missing files (there will be more than just nunit.framework.dll) in the same directory as nunit-console.exe.
There might be a command line option either in mono or nunit-console.exe to specify another directory to search for missing DLLs -- I'm not sure. Barring that, you'll have to copy the missing DLLs into the same folder as nunit-console.exe, or you'll have to cd into the framework folder and use mono ../nunit-console.exe /path/to/my/tests.dll
Once nuget is installed, you can use it to install nunit.console like so:
(This is from my .circlci/config.yml file)
- run: mono --runtime=v4.0 nuget.exe install nunit.console
- run: msbuild MySolution.sln
- run: mono --runtime=v4.0 NUnit.ConsoleRunner.3.12.0/tools/nunit3-console.exe FirstModule.Tests/bin/Debug/FirstModule.Tests.dll
- run: mono --runtime=v4.0 NUnit.ConsoleRunner.3.12.0/tools/nunit3-console.exe SecondModule.Tests/bin/Debug/SecondModule.Tests.dll
The trick is to specify the entire path for the NUnit.ConsoleRunner and to watchout for the - changing into a . by version 3