NUnit Throwing InvalidOperationException: Service Manager failed to initialize RecentFilesService - c#

My laptop did a bluescreen when I was running some unit tests, and now nothing I can do will make it able to run tests again.
I am attempting to run tests that are programmed against NUnit 3.2 using Resharper, although Resharper reports that the problem is in NUnit. I pulled the NUnit code down from GitHub and it looks like the error is thrown if the RecentFilesService is unable to find a particular setting from the settings file. I have searched my computer for this file and cannot find it. I have reinstalled all of the NUnit packages in my project as well as reinstalled Resharper.
At this point, I am pretty much DOA. I need to figure out how to reset this file to its correct state, or else simply bypass this error.

I was able to track down the problem to the file Nunit30Settings.xml, which had become corrupted and was full of null characters. I deleted the file and everything ran fine and the file was regenerated. This file is in your [User]\AppData\Local\NUnit folder.

#drz, thank you for above information. It was very helpful. I can not comment or vote so adding your answer here
"Nunit30Settings.xml, becomes corrupted so delete the file at
[User]\AppData\Local\NUnit folder. File will be generated again."

Related

Sonar - Code Coverage Reported, but Unit Test Count Not Reported

Recently, I've been running into a perplexing issue regarding Sonar that I can't seem to figure out. I couldn't really find anything on this specific issue online, so I figured I'd reach out and see if anyone has experienced this as well.
I am using the following:
Sonar 6.0
TFS 2017 Update 1
SonarQube VSTS Extension 2.1.1
Build server with Visual Studio 2017
When I am performing Sonar analysis after a build and after tests complete, it is detecting both the resulting trx file and coverage file.
But once the analysis is done, it only reports code coverage. It does not report the unit test count.
Originally, I was using the following arguments in the "Additional Settings" in the Sonar Begin Analysis step to specifically point it to the trx:
/d:sonar.exclusions=**Scripts**,**Content** /d:sonar.cs.vscoveragexml.reportsPaths="$(Common.TestResultsDirectory)\*.coverage" /d:sonar.cs.vstest.reportsPaths="$(Common.TestResultsDirectory)\*.trx"
But I just tried removing all those arguments as I was told by a sonar rep in the past that you want to specify parameters from the site instead of by command line. When I removed my parameters, nothing changed (which I guess is to be expected). It still was able to find the trx file and still did not report unit test count.
I would try adding the vstest report path in the UI, but the issue is the path and file name are dynamically generated. The path depends on what build server/vsts agent the build is sent to, and the trx file name is generated based on date-time, and as far as I could find, there is no way to force the trx file to have a specific name.
I also checked the trx file to make sure I could open it and it reported test data.
Essentially, as far as I can tell, it should be reporting the unit test count. It did in the past but seems to have been not working as of recently. I'm not sure if this maybe was fixed in a newer version of Sonar? Unfortunately, I can't upgrade because dashboards were removed in newer versions of Sonar, and the organization I work for uses them. Has anyone experienced this issue before, and if so, were you able to fix it? Let me know if you need any additional information!
Try to use /d:sonar.cs.vstest.reportsPaths=..\**\TestResults\**\*.trx instead (Additional Settings).
On the other hand, there is SonarQube 2.1.2 aviable.
My result: https://1drv.ms/i/s!AresBGZVYryjhSpb9taJWFht7YB9

Error "mscoreei.dll not found" in VS2015 debugging

When I'm trying to debug my dump file I get an error:
mscoreei.dll not found
mscoreei.dll was not found in the minidump. You need to load the binary in order to find the source for the current stack frame.
I have a project in C# that can hang sometimes on other computer. Each time as it hangs, 'procdump' app creates minidump file for me. Previously, I could normally open this dump file in VS2015, which shows me a stuck place in the source code.
Everything works fine till I made a 'clean up' in the repository. I didn't add any line in the code, I just clean up repository and all my .pdb files were exterminated. I build project again to restore .pdb files. But now as I try to debug dump files, VS2015 shows me page "No Binary Found" with error message written above.
I didn't make any changes in the source code. I didn't modify my environment. Debugging stops working as I made repository clean up.
When I'm checking 'Stack Frame' list, then evrything that is coming after "mscoreei.dll!7311ffcc" have format "[Frames below may be incorrect and/or missing, no binaries loaded for filename]".
I found the problem. It turns out, that my environment changed. From the last build when debugging worked correctly, Windows Update service updated my .NET library. As result my new build is using updated .NET files, but dumps are created for old .NET. Restoring correct version of .NET helped me.

csc2.exe exited with code 1

I'm playing with VS2015 and C# 6.0 compiler. Everything it great, but I suddenly started getting strange compilation error on one of my projects:
"csc2.exe" exited with code 1.
I would love to provide as much data as needed, but I guess I don't have much:
I have several project in the solution. All projects (excluding the project where I have unit tests) still compile without any problems.
Quick googling did not help.
I've looked into output, there isn't much: C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.CSharp.CurrentVersion.targets(383,9): error MSB6006: "csc2.exe" exited with code 1.
VS restart as well as reboot didn't helped.
Rollback of latest changes (but I can't give you 100% that I rolled back all of them) didn't help.
I'm stuck! I would appreciate any advice.
UPDATE
As #rene suggested I run MSBuild.exe with /v:diag. In the produced output I could finally find the root of the problem: I mistyped enum member name. I usually expect to see such errors in the error list, but they are not there until I open the file (where the error is taking the place). As soon as the file is opened in the VS, I can perfectly fine see all errors in the error list.
Hope that this will be fixed by the next CTP.
In my case, i was remote debugging my project dll through another visual studio. When I try to delete obj folder it failed to delete .pdb file. That triggered me that I have a visual studio left running. Closed it, retry build, boom, it worked fine. Just in case, check obj folder for any pdb file locks. That could also be a reason.

Unit Test Adapter threw exception with no stack trace in TeamCity 7.1.5

We have an ASP.NET MVC 4.5 project. For months it has been compiling and all unit tests passing locally on our development machines and on the TeamCity 7.1.5 machine. Monday we updated to newer versions of some of our dependencies (specifically, to get OData 5.0.0-rc1 for select-expand).
The project compiles fine on our development machines and the build machine. It runs fine on our development machines and on both QA environments it's deployed to. All the unit tests pass on our development machines. However, about half (~300) of the unit tests now fail when run from TeamCity using the MSTest build runner, all with the same, useless error:
Unit Test Adapter threw exception:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
I've tried everything imaginable. At first I figured there was a legitimate problem. Since there's no way to retrieve the LoaderExceptions property from TeamCity (why doesn't MSTest just display more information!?!?), I logged in to the machine TeamCity is running on, opened up the console, changed into the work directory that our build is running from, and ran the tests manually so that I could retrieve the property. ALL OF THE TESTS PASSED! There goes that theory...
After an entire day of Googling and reading other answers on StackOverflow, I've tried about two dozen different combinations of the following steps:
Changing the build from "Rebuild" to "Clean," running it without tests so that it just cleans, changing it back, and running it again.
Changing the build from "Debug" to "Release," running it, and changing it back again.
Cleaning agent sources from TeamCity admin pages.
Manually deleting entire work directory off of the agents, skipping the recycle bin and going straight to the netherworlds.
Deleting all source control (TFS) caches off the build machine and agents.
Telling TeamCity to clean the work directory before getting latest from source control.
I've reached the end of my troubleshooting capabilities. The tests just won't run anymore on the build machine, for apparently no reason at all.
What can I do? What the heck is going on?
The short answer to this is, "It's a bug."
I reported the bug to JetBrains. It appears that, though there might be some underlying problem with my project, it's only a problem when run from Teamcity, and it's impossible to retrieve the actual error message, so there's no way to know what that problem is. The runner should be catching the exception and printing out the LoaderExceptions property, but it isn't. Instead, it's just calling ToString() on the exception. The runner will have to be updated to look for this specific exception and print the LoaderExceptions property. Once that happens, then we can see the underlying problem, which may result in changing something in the project, or it may result in filing another bug with JetBrains.
Workaround
I spent quite some time debugging our Continuous Integration build failure while experiencing this bug. Since Jetbrains doesn't address the issue, I thought I'd post my workaround here so others have something to work with.
My problem was that the build failed on the step which runs the unit tests. Coincidentally the build which failed added a unit test project. When the newly added unit tests were excluded, everything ran successfully. Because of the reasons stated above and Teamcity not handling the exception properly, debugging options are limited.
I never found a solution which doesn't get your hands dirty, but what you can do is the following. It's basically manually running MSTest versus the test assemblies on the build agent and does require remote desktop access to it. In my case, Teamcity ran the unit tests from the following directory:
C:\BuildAgent\temp\buildTmp[NAME TIMESTAMP]\Out.
Run the following command to initiate the MSTest runner on the assembly which contains failed tests:
C:\BuildAgent\temp\buildTmp\Out>"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\MSTest.exe" /testcontainer:"C:\BuildAgent\temp\buildTmp[NAME TIMESTAMP]\Assembly.With.Failed.Tests.dll"
The output should give you the problem which actually makes the tests fail. In my case it turned out that the new project had a reference to Ploeh.AutoFixture with a different version than the version used in the other unit test projects.
Unable to load the test container 'C:\BuildAgent\temp\buildTmp\Out[NAME TIMESTAMP]\Assembly.With.Failed.Tests.dll' or one of its dependencies. Error details: System.IO.FileLoadException: Could not load file or assembly 'Ploeh.AutoFixture, Version=3.18.10.0, Culture=neutral, PublicKeyToken=b24654c590009d4f' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).
Specific problem solution
In case you're wondering how to fix a similar issue, you can do the following. Open the package manager console (View -> Other windows -> NuGet Package Manager) and execute the following command.
Install-Package Ploeh.AutoFixture -Version 3.18.10.0
This adds the NuGet package (to the project selected on the dropdown) with a specific version, just make sure that all the projects are aligned in this sense.

Test method is inconclusive: Test wasn't run. Error?

I have a test class and below I have posted a sample test from the test class
namespace AdminPortal.Tests.Controller_Test.Customer
{
[TestClass]
public class BusinessUnitControllerTests
{
private IBusinessUnitRepository _mockBusinessUnitRepository;
private BusinessUnitController _controller;
[TestInitialize]
public void TestInitialize()
{
_mockBusinessUnitRepository = MockRepository.GenerateMock<IBusinessUnitRepository>();
_controller = new BusinessUnitController(_mockBusinessUnitRepository);
}
[TestCleanup]
public void TestCleanup()
{
_mockBusinessUnitRepository = null;
_controller.Dispose();
_controller = null;
}
#region Index Action Tests
[TestMethod]
public void Index_Action_Calls_GetAllBusinessUnit()
{
_mockBusinessUnitRepository.Stub(x => x.GetAllBusinessUnit());
_controller.Index();
_mockBusinessUnitRepository.AssertWasCalled(x=>x.GetAllBusinessUnit());
}
}
}
When I run the project I get following screen
I checked the references and the test project has the reference to main project.
Any idea why the test are not running or saying that they were inconclusive?
Edit 1:
I saw a post here and changed my test's setting's default processor architecture to X64 but it still doesn't work.
Just in case none of the above options worked for anyone I fixed my instance of this error by noticing a corrupt entry in my App.Config due to a missing nuget package in the test project.
For me it was rather frustrating, but I've found solution for my case at least:
If your TestMethod is async, it cannot be void. It MUST return Task.
Hope it helps someone :)
I had the same issue with resharper and I corrected this error by changing an option:
Resharper => Options => Tools => Unit Testing
I just had to uncheck the option "Shadow-copy assemblies being tested"
It was a Resharper issue. In Resharper options->Tools->MSTEST, I unchecked the Use Legacy Runner and now it works.
I faced this problem in vs 2017 update 3 with Resharper Ultimate 2017.2
Restart vs or restart machine can't help.
I resolved the problem by clearing the Cache as follows:
Resharper ->options-> Environment ->click the button 'Clear caches'
Update:
There is a button "error" (I find in Resharper 2018) in the upper right corner of the test window.
If you click the error button, it shows an error message that may help in resolving the problem.
To track the root of the problem, run Visual Studio in log mode. In vs 2017, Run the command:
devenv /ReSharper.LogFile C:\temp\log\test_log.txt /ReSharper.LogLevel Verbose
Run the test.
Review the log file test_log.txt and search for 'error' in the file.
The log file is a great help to find the error that you can resolve or you can send the issue with the log file to the technical support team of Resharper.
For me, simply cleaning and rebuilding the solution fixed it.
I was having this problem, and it turned out to be the same as this problem over here. This answer solved the problem for me.
Uncheck "Only build startup projects and dependencies on Run" (Options -> Projects and Solutions -> Build and Run)
In Configuration Manager, make sure both the start-up project and the Test project have "Build" checked.
The second time I hit this issue, it was due to an ampersand in the filepath to the project where the tests reside. It works fine with ReSharper's test runner, but not dotCover's. Remove the ampersand from the filepath.
This is a confirmed bug with dotCover.
For me, the problem was a corrupt NUnit/ReSharper settings XML-file (due to an unexpected power shortage).
To identify the error I started Visual Studio with this command:
devenv.exe /ReSharper.LogFile C:\temp\resharper.log /ReSharper.LogLevel Verbose
Examining the file revealed the following exception:
09:45:31.894 |W| UnitTestLaunch | System.ApplicationException: Error loading settings file
System.ApplicationException: Error loading settings file ---> System.Xml.XmlException: Root element is missing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at NUnit.Engine.Internal.SettingsStore.LoadSettings()
--- End of inner exception stack trace ---
at NUnit.Engine.Internal.SettingsStore.LoadSettings()
at NUnit.Engine.Services.SettingsService.StartService()
at NUnit.Engine.Services.ServiceManager.StartServices()
at NUnit.Engine.TestEngine.Initialize()
at NUnit.Engine.TestEngine.GetRunner(TestPackage package)
at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.<>c__DisplayClass1.<RunTests>b__0()
at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.WithExtensiveErrorHandling(IRemoteTaskServer server, Action action)
Note that this is NOT the test project's app.config!
A quick googling around identified the following file as the culprit:
%LOCALAPPDATA%\NUnit\Nunit30Settings.xml
It existed, but was empty. Deleting it and restarting Visual Studio solved the problem.
(Using Visual Studio Professional 2017 v15.3.5 and ReSharper 2017.2.1).
My problem was that I had only installed NUnit with nuget. I hadn't installed NUnit3TestAdapter which was also required.
Install-Package NUnit3TestAdapter
I just fixed this issue as well. However, none of the solutions in this thread worked. Here's what I did:
Since R# wasn't giving any detail about why things were failing, I decided to try the built-in VS2013 test runner. It experienced the exact same behavior where none of the tests ran. However, looking in the Output window, I finally had an error message:
An exception occurred while invoking executor
'executor://mstestadapter/v1': Object reference not set to an instance
of an object.
This led me to another thread on SO with a solution. Believe me, I would have NEVER guessed what the issue was.
I had recently made a few changes to the AssemblyInfo.cs file while creating a NuGet package. One of the changes including specifying an assembly culture value of "en".
I changed this:
[assembly: AssemblyCulture("")]
to this:
[assembly: AssemblyCulture("en")]`.
That was it! That's what inexplicably broke my unit tests. I still don't understand why, however. But at least things are working again. After I reverted this change (i.e. set the culture back to ""), my tests began running again.
Hope that helps somebody out there.
In my case i got this error because of 'Release' mode where build of UnitTests project was simply switched off. Switching back to 'Debug' mode fixed it.
It's really surprising that ReSharper cannot say anything in case it cannot find UnitTests library at all. Seriously, it's a shame;)
Hope it will help somebody
In my case [Test] methods were just private. S-h-a-m-e
This error occurred with Visual Studio 2017 and resharper version 2018.2.3 but the fix applies to Visual Studio 2019 versions to.
The fix, to get tests working in Resharper, was simply to update to the latest version of Resharper (2019.2.1) at the time of writing.
In my case it was a mistake i did while copying the connectionstring in the app.config..
I had put it inside the configSections tag!
Took me a while to realize that... thanks VS intellisense though.. or was it resharper?
I had similiar issue. VS 2010, c# CLR 2 Nunit 2.5.7 , just build > clean solution from VS helped to resolve this issue
In my case I created an async test method which returned void. Returning of Task instead of void solved the issue.
In my case, all tests within some test projects within a solution started not running after I added new projects. Using VS 2017 with ReSharper 2017.1.2 here.
First of all, make sure you're not wasting time assuming that your issue is ReSharper related. It is easy to assume that there's something wrong with ReSharper if you use its unit testing features including Unit Test Explorer. Open up Visual Studio's Test Explorer under the Test menu and try Run All". The added advantage of doing this is that the output window will show an error message that might point you in the right direction. If you notice that the same set of test are not run, then it is safe to assume that the issue is with Visual Studio and not ReSharper.
I ended up deleting and re-adding one of the Active solution platform, Any CPU, in Configuration Manager. By doing so, after saving my changes and reopening the solution, all tests started running again.
I believe there was an unexpected configuration entry in the solution file when I added new projects and by using recreating one of the platforms, it corrected itself. I tried diffing but it was difficult to tell what had changed to cause the issue.
Have you added any DLL dependency recently? ... like me
I just ran into the same issue and it was very exasperating not to get any clue in the test output window or elsewhere practical.
The cause was extremely stupid: I just added the day before dependency to an additional external DLL in a sub-project, and the main project App indeed built and ran correctly after the change. But my unit tests are in a sister project to the main app, and thus had too the dependency on this changed sub project where the DLL was invoked... yet, the runtime location of the test project is not that of the main App!
So changing the build to do copying of the missing DLL into the test runtime directory fixed the problem.
I am using VS2013, ReSharper 9.1 with MSpec extension from ReSharper and Moq. I experienced the same "inconclusive" error.
It turned out the one of my Mock's from Moq was not initialized, only declared. Ones initialized all tests ran again.
In my case my test method was private I changed it to public and it worked.
For those who are experiencing this issue for my test project .NET Core 2.0 in the Visual Studio 2017 Community (v15.3 3). I also had this bug using JetBrains ReSharper Ultimate 2017.2 Build 109.0.20170824.131346 - there is a bug I posted.
JetBrains advised to create a new test project from scratch to reproduce it. When I did that and got tests working OK, I found the reason causing the issue:
Remove this from your *.csproj file:
Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}"
When I did that - tests started working fine.
For who are in rush for test execution, I had to use VS 2017 test explorer to run tests;
I'm using VS2010, NUnit 2.6.3 (although internally ReSharper says it's using 2.6.2?), ReSharper 7.7.1 & NCrunch 2.5.0.12 and was running into the same "...test is inconclusive..." thing with NUnit, but NCrunch said everything was fine. For most of today NUnit & NCrunch were in sync agreeing about which tests were happy and which needed refactoring, then something happened which I still don't understand, and for a while NCrunch said I had failing tests (but stepping through them showed them to pass), then decided they were all working, and NUnit started complaining about all my tests except one with the same message "..test is inconclusive..." which I was again able to single step through to a pass even though NUnit continued to show it as "inconclusive").
I tried several of the suggestions above to no avail, and finally just closed VS2010 & reopened the solution. Voila, now all my tests are happy again, and NCrunch & NUnit are reporting the same results again. Unfortunately I have no idea what changed to cause them to go out of sync, but closing & reopening VS2010 seems to have fixed it.
Maybe someone else will run into this and be able to use this simple (if ultimately unsatisfying since you don't know what the real fix is) solution.
I had this same issue. The culprit was an external reference not being compatible with my project build settings. To resolve, I right clicked on the project->properties->build->Platform Target-> change from Any CPU to x86.
The particular *.dll that I was working with was System.Data.SQLite. That particular *.dll is hardcoded for 32 bit operation. The "Any CPU" setting attempted to load it as 64 bit.
My solution:
NUnit 3.2.0 has some issues with Resharper - downgrade to 2.6.4:
update-package nunit -version 2.6.4
Caused by missing (not corrupt) App.Config file. Adding new (Add -> New Item... -> Application Configuration File) fixed it.
I had the same problem.It was related to compatibility version between NUnit 3.5 and Resharper 9.2,since it was solved by downgrading from NUnit 3.5 to 2.6.4.
It worked for me.
good luck.
If you are using xUnit, I solved the issue installing xunit.running.visualstudio package.
(currently using xUnit 2.3.1 and VS17 Enterprise 15.3.5)
I'm was having the same problem to run any test using NUnit framework. "Inconclusive: Test not run"
Visual Studio 2017 15.5.6
ReSharper Ultimate 2017.3.3 Build 111.0.20180302.65130
SOLVED Adding project dependency to Microsoft.NET.Test.Sdk
I had the exact same problem, no tests were run in my test-project. As it happend I had the wrong configuration selected when running the tests. Changing it back to Debug fixed the problems.

Categories

Resources