Visual Studio 2017 TestMethod No error on run, just after - c#

Hi diddaly hodely neighboronies!
I am currently making a test project to make sure my project is working correctly.
All of the tests work fine except one. It finishes the test with no errors as seen below...
It then updates the Passed Tests list...
However, a few seconds later when it's done it outputs this message:
An exception occurred while invoking executor
'executor://mstestadapter/v2': Object reference not set to an instance
of an object.
And the test is no longer lit up indicating passed.
Me and a friend have been googling this all day and have found the issue on a few pages, with completely different answers, none of which solved our problem.
Has anyone else had this issue and solved it? Please share!

Turned out to be a DLL that was being executed but didn't report back errors. I doubt this will help many people, but check your references and make sure it has what it's looking for. I'm assuming this is because it's using the Test path instead of the project it's tied to. Good luck to those who are haunted by this issue.
UPDATE: Yup it was the reference issue, but it is running on a separate thread. Youch! Check your threads!

Related

XUnit ignore a test unless specifically triggered

I have 2 xunit tests I want to be ignored when triggering Run All Tests from VS, and to only run if the user ran it/them specifically.
I've tried using [Fact(Skip = "Long test, only run if needed, and run independently")] (or whatever message), however then it shows warnings, and the overall run's result is yellow like so, even though the rest passed:
I've found solutions on here that potentially allow this to be done via Resharper, however we do not have resharper available to us (I know... it sucks). I've also looked into SkippableFacts, but I believe these will lead me to the same result as in the above picture. Not to mention when you try to run it on it's own it always skips as well, and you need to change it to a regular [Fact]
Does anyone know of any possible way to ignore a test unless intentionally, specifically, and individually triggered? Any other paths to try would be really helpful, I'm stumped. Thanks!
In XUnit library you can use Fact or Theory (as the case may be) with the Skip attribute.
[Fact(Skip = "Reason")] or
[Theory(Skip ="Reason")]
This will skip the test and overall result should be green. It is working for me in my Asp.Net Core application.
Create playlists in VS (or 'Session' in Rider). One with the tests you always run, and a second one for the tests you only intend to run sporadically.

Unity: InvalidProgramException: Invalid IL code XXX(): IL_0011

So the project is an online MMO. It uses the uMMORPG2D asset (which in turn uses UNET).
The code in question has been working fine for the last week without incident, and hasn't been modified in any way in that time at all. However now it suddenly is throwing this error. I'm at a loss.
To complicate matters further, on my own build/version of the project it all runs fine. I do not get this error. However a friend who runs the exact same build/version does get this error.
The line that is claiming to be broken is extremely simple (couldn't be simpler). All it does is it sets one integer equal to another....the only potential problem is the integer being set is a [SyncVar] (but again, this has been the case for the last week+)
Below is the relevant code;
[SyncVar]
internal int mainID = 0;
public void SetIndices(int bodyIndex, [...])
{
mainID = bodyIndex;
[...]
}
SetIndices gets called from
int bodyID = Convert.ToInt32((long)mainrow[5]);
[...]
charCreator.SetIndices(bodyID, [...]);
There is no cast exception or anything of the sort (as far as I know) so I see no reason why this would cause an error?
The actual error is
InvalidProgramException: Invalid IL code in
CharacterCreator:set_NetworkmainID (int): IL_0011: call
0x2b00000a
Whilst I'm not exactly certain as to the actual cause of the problem,
the solution was to reinstall Unity.
I was advised by team members to implement HLAPI Pro plugin for Unity (which involved replacing Unity.dll files in the installation directory). I was told that an incorrect installation would result in many errors (which no one had) so assumed it worked fine.
After significant testing, the only difference between when it was working, and when the error started to show was the HLAPI Pro installation. So I uninstalled it and it was working fine.
Don't know why it broke, perhaps I installed it incorrectly, but reinstalling Unity resolved the issue.

Visual Studio displayed lots of errors, but there is only one actual error

I have a custom control library in my solution, where my main WPF project references it. If there is an error in the custom control library, then the error list goes mental and displayed hundreds of errors. Here is an example of one such incident.
Now this is just an error that I forced in order to demonstrate the problem.
In this case, the problem isn't so severe, as there are only 21 errors. However, there have been occasions where I have had to filter though hundreds of errors to find the actual error that's causing everything else to fail.
I believe I understand what the problem actually is. I think the problem is due to the custom control library not being built, therefore my main project can't find the dll for it, and therefore the custom controls cannot be found, which causes the errors.
Now, in truth, the error list isn't lying, I mean, these are real errors. However, that being said, is there a way to prevent this from occurring?
If I understand what you are asking, I think that this extension will help you as it stops the build as soon as an error occurs.
StopOnFirstBuildError

Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible

Here is the error
Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized.
I am writing a simple console app and the first line of code is this:
List<MyObjectModel> list = MyObjectModel.GetNonCompletedReturns();
and the code for the function is:
public static List<MyObjectModel> GetNonCompletedReturns()
{
MyObject service = new MyObject();
List<MyObject> entities =
(from recs in service.Retrieve() where select recs).ToList();
List<MyObjectModel> models = new List<MyObjectModel>();
foreach (MyObject entity in entities)
{
models.Add(BindModel(entity));
}
return models;
}
and if I try to step through the code, as soon as I get back to the main of my app and hover over the list, I get the error message that I showed.
Can anyone help?
If your project is compiled in release (with optimizations turned on), you may see this. Have you tried the DEBUG configuration?
This error fires only when you are trying to use Watch dialog during debug.
Try to use some other technique to output the variables, like Debug.WriteLine, Console.WriteLine and so on.
None of the answers solved my problem so I'm posting the solution that helped me.
"If there is to much data in the parameters then this error can occure,
a simple solution is to make an object, not a struct because that's a dataobject.
Put this object in your parameters instead of all the different variables,
normally the problem will no longer take place."
Here's a little trick just in case you want to examine some objects and you are not able to change the parameters:
I've created a call to a new temporary function, inside the function from where I was unable to watch my object. Then, inside that new function I was able to watch my object. After the job is done, just delete the function.
While it's true that the "Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized" error appears when in release mode, most developers just ensure that their projects are configured to compile as a debug build. BUT to be sure that you have no release-DLL issues, you also must check the references to DLLs that are in your solution and make sure that you don't have a reference to a release-build DLL. If you find that this is the case, delete the DLL reference and then add a project reference rather than a DLL reference. The project reference will ensure that your solution references debug or release versions of the DLL as specified in your build configuration.
Note that the above advice applies, of course, to only those DLLs to which you have source code and which are built from a project in your solution.
I got this too, when I hit a NullReferenceException from a 3rd party control.
In this one case, I found that if I set a breakpoint before I hit the exception, I could then single step through the rest of the code without seeing the problem.
No idea why, but this worked for me - in this case at least.
For what it's worth, this error can also be caused by an infinite loop in a property getter (simplified version below). When the debugger attempts to evaluate the property (e.g. in the watch window) the UI will hang for a few seconds and the "Cannot evaluate expression..." error will appear for many of the other properties in the same class.
public int MyProperty
{
get
{
while (true) { }
return 0;
}
}
First make sure that you're running your code in DEBUG mode and with code optimization turned off. you can turn that off from the properties of your project.
If you made all of the above and the problem persists, then it's probably a problem with the stack having Debug.Break() on top of it. The solution for this is very easy, just press F10 to move to the next line and you should be able to evaluate the expression.
You can check this SO question for more information about this issue.
I was experiencing the same error message in the Visual Studio debugger when evaluating a linq expression.
Disabling the VS debugger config setting 'Enable Just My Code' resolved the issue for me:
To enable or disable Just My Code, choose the Tools > Options menu in
Visual Studio. In the Debugging > General node, choose or clear Enable
Just My Code.
https://learn.microsoft.com/en-us/visualstudio/debugger/just-my-code
I was having same issue in Visual Studio 2017. Going to Debug> Options> Debugging> General and checking "Suppress JIT optimization on module load(Managed only)" fixed my issue

Odd problem unit testing internal classes with VS 2008

I'm starting a project which is broken up over multiple VS projects and I was planning on having separate testing projects for each of the projects, so I'd have a solution like this:
Project1
Project1.Test
Project2
Project2.Test
There are some internal classes which I want to have tested. So I used Visual Studio 2008 (SP1) to generate the test stubs in my test project and added the InternalsVisibleTo. But I get a red squiggly line under the internal class. If I compile I get a successful build, and looking at the test method the red squiggles are gone.
But if I tough the file the squiggles come back and I have no intellisense on the internal class.
The internal is within Project1 and the test is within Project1.Test. For completeness I decided to do the exact same manner of generating the test method but this time into Project2.Test, and this time it's shown to be completely working. I don't get red squiggles, I get intellisense, everything.
I've tried deleting Project1.Test and recreating the test method, everything I can think of, but no matter what I do I can't get the internal to be completely visible within its paired Test project, only in the one which is designed to be for another project.
It's doing my nut that it's not working!
I've seen this too, especially when using strong names. To be honest, I didn't get excited; as long as it compiles and tests correctly, I can live with the odd glitch. For example, if you get one build problem, I've seen it complain that it can't find the other (internal) methods - but a clean build shows no errors. Again, I'm not to bothered by this... (maybe I'm too forgiving?).
In particular, it is only rarely that I need to use an internal type/member in the tests (most of the time I'll try to test via the public API); so the lack of 100% reliable intellisense isn't usually a big problem. I already know the type/member I am looking for (copy/paste ;-p).
Sure, it would be nice if it was fixed, but if I was the budget manager, I could probably live with it and focus on other features first.
Could you be using a string constant or something other than the exact literal stirng (without concatenation) in your InternalsVisibleTo attribute? We had the habit of using a string constant to define it, and that works fine for everything except intellisense. Replace by pasting as a simple string and it works.
Deleting your .suo file (same folder as your solution file) might help as well.
It might be a problem with IntelliSense DB file. Try to delete it and have VS try and rebuild the DB.
To do this close the solution and delete (all?) .ncb files. To be on the safe side, just rename them to something like .nc4 or whatever. Reopen the solution and rebuild it. Let me know if it works.
EDIT: Apparently, ncb files are only for C++ projects. I don't know where the IntelliSense DB for C# projects are, nor could I find out. If I were you, I would still try to find a way to reset the DB.
Asaf

Categories

Resources