Visual Studio Unit Test - The member specified could not be found - visual-studio

Getting an odd problem with a unit test in my solution. One of the test always fails with the following error message:
The member specified (BuildMap) could not be found. You might need to regenerate your private accessor,
or the member may be private and defined on a base class. If the latter is true, you need to pass the type
that defines the member into PrivateObject's constructor.
BuildMap is private and I have tried regenerating the accessor, changing it to public and recreating the unit test and it continuously fails. The other methods (both public and private) all work fine. BuildMap is also not defined in a base class.
Also tried all the usual things in case VS is messing about, restarting it, clean assemblies, rebuild etc...
Any ideas on the cause?
update 1: This is in Visual Studio 2008 or on the command line mstest tool.
update 2: Tried renaming the BuildMap method and the tests would not build stating it was missing. Appears that Visual Studio/MSBuild is doing the right thing, but somewhere between it and mstest it is breaking.

Oddly enough when I changed the method from static to not static the issue resolved itself. Other private static methods work fine though.
Still not sure of the cause but that is the resolution.

Related

VS2013 Express not Compiling as normal

Just having an annoying issue with VS not compiling correctly and showing a bogus compile error.
Error 1 'ConcurUtility' is not declared. It may be inaccessible due to its protection level. <path>\App_Code\AppUtility.vb 22 34 KWAI
Error 2 'T' is not a member of 'System.Text.StringBuilder'. <path>\App_Code\AppUtility.vb 30 16 KWAI
It says my class is not declared when it clearly is as it comes up in intelli-sense. It is declared public and my method I am calling is
Pubic Shared Function GetDocument(...
I have commented out my call to the function and it does compile then so it cannot be the ConcurUtility class that is causing the issue.
I have rebooted my machine and it is still not working. I have cleaned and tried to rebuild but to no avail. Any ideas what is causing this problem.
You should troubleshoot your second error instead. I guess ConcurUtility was not public in the last successful build, and VS is still considering it as protected/internal based on that.
I believe the Project File must have been corrupt (who knows) as I started from scratch and added every class in manually then copied and pasted my code from my old project to the new one and it works fine. Just one of those things that perhaps the express version must have a unknown bug because it is hard to reproduce. I.e. the clean does not really do a thorough clean.
The only thing I can recall is I created the class under a different name and renamed the call before renaming the class and file and somehow this has been cached and so it no longer complies. Not worth my effort figuring it out. Tis one of those unsolved mysteries.

How to compile Shadows events using MSBuild

I am trying to use set up a CI server that doesn't depend on a Visual Studio installation but uses msbuild instead. Our solution includes an interop project. Visual Studio handles this project just fine, but msbuild seems to have a problem with events like this one, taken from an interop user control which inherits from System.Windows.Forms.UserControl:
Public Shadows Event Click() 'Event must be marked as Shadows since .NET UserControls have the same name.
The error I get from MSBuild is this:
error BC30029: Derived classes cannot raise base class events.
I read this, but my Event statement and RaiseEvent statements are already in the same class (the one from which the above error is being thrown). I don't think this solution applies to my situation.
What's the best way to get around this? Let me know if you need more information.
Thanks.

Nunit not running SetUp method in Visual Studio debug mode

I'm trying to debug into the tests after the setup method is called and the tests depend on the setup method being called.
I'm using Nunit 2.6.0.12051 testing a .Net 4.0 class library. The nunit Visual Studio project has a class marked with [SetUpFixture] and a method marked with [SetUp].
If I run the tests from the NUnit gui, I'm fairly certain the setup attrib'd class is called (because it isn't stopped at the setup class with a run-time error now) but I can't debug into it. If I try to change the settings to see Verbose Tracing, NUnit gui throws an unhandled excption.
If I run the tests from Visual Studio via Test View/Debug Selection, the break point at the setup method doesn't stop execution and the trace statements inside the method don't print in the debug window. So I'm certain the setup method isn't getting called.
While I could just change the setup class to be the base of all test classes, I only need the method run once.
Any help would be wonderful.
I just ran into this issue and eventually found this significant sentence from the NUnit SetUpFixture documentation:
"This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace."
Turned out my SetUpFixture class was in an entirely different namespace than my tests, so it wasn't being run.
I just noticed the same when using the latest NUnit from NuGet (2.6). The [Setup] method is not run before the [Test] -methods.
I don't know why they changed this quite significant part of NUnit, but I fixed it for my purposes by going back to version 2.5.10 which does run [Setup] before [Test].
I had this issue too but installing the latest version of the test runner (TestDriven.NET in my case) fixed it. It wasn't an NUnit issue for me.
I just ran into a similar issue. My unit test was not calling setup either. After reading the NUnit doc. referred in the top answer, I figured my solution was extremely simple.
In very simple terms, I was missing the "Setup". Realised after reading the doc.
*Example from NUnit SetUpFixture doc mentioned in top answer.
[SetUp]
RunBeforeAnyTests()
{
//
}
----------------------------------------------------
// this was my fixed up code
// simply added [Setup] and boom, bob is your uncle.
[SetUp]
public void Setup()
{
readChoice.Reset();
}

Part-time bug with extension-methods

I'm currently dealing with a part-time (and annoying) bug with some extension methods in VB .NET (VS 2010 and VS 2008).
I have some client projects that use some extension methods from a "Framework" Project I created for general purpose.
However, sometime, when a try to start the solution, I get a long list of error saying the extension method "is not a member of" target object.
When this happen, I can rebuild the solution without getting any error but if I start the project again, the same error will be raised again.
So far I have 2 workaround
A) Go on the extension method definition, delete the tag, compile (with error), put the tag back.
B) Close Visual Studio et re-open it.
Is there any betterway to handle this problem?
There is an active bug report for this problem at Connect. There's a dire need for a repro, a project with specific steps to let them reproduce the issue in-house. Perhaps you can help, it's what it will take to solve it or recommend a workaround.
EDIT: one late addition to this answer, since I've posted this there have been additional questions that note a problem with the IntelliSense parser behaving different from the compiler. There's an issue with the multi-targeting feature, particularly in VS2010, triggered by the Client Profile option for .NET 4. It is the default for a new project. What goes wrong is adding an assembly reference that requires the full profile, commonly because of a dependency on System.Web. You'll get a warning for that, but that's quickly blown away with a large number of errors. The fix is to change the project's Framework Target from client to full.
I've recently encountered this same issue. My project would Build just fine but if I tried to use the Rebuilt option I would get the error about my extension methods not being found on the objects they were extending.
I have managed to fix this today by including an Import at the top of the classes using the Extension method.
So at the top of the file I actually have
Imports project_name.extension_module
I have no idea why this is required but it fixes the problem in my case. I hope this helps somebody else that has wasted as much time with this as I have!
Liam
A less time consuming work around than the two you listed is to "Rebuild Solution" instead of the normal Build Solution. This has always worked for me whenever I run into this problem.
We have something very similar. Call extensions merhod that extends type A. type is actually an instance of type B that implements interface C. interface C has a method with the same name as extension method.
Interface C declares method Foo
Class B inherits from A implements C
Static Class
Static method Foo (this A)
If A is C
(A as C).Foo
When debugging on the line if A is C it actually calls Foo multiple times and you can step at assembly level and see it indicates it is doing the comparison. The way we demonstrate that the call is happen Foo executes a sql statement and we can see sql profiler executing the code in Foo.
Change A as C to reflection and bug goes away. Or use debugger hidden/step through and bug is masked. Also if you micro-step the sql profiler shows the query is getting called multiple times (before Foo is actually called) for each assembly statement.

VS2008 Unit Test Project bugs

I'm using VS 2008 Developer Edition and am finding some bugs with the Test Projects.
I am getting one error that doesn't make sense - I have a class called 'Foo' which I need to test and created the blank test class automatically.
Foo takes 3 paremeters in its constructor - IBar, IBaz, IBang.
When I write a test case, I will Dim foo as New Foo(bar,baz,bang), and I will sometimes get an error that says = 'Type IBang could not be implicitly converted to IBang'. This error does not make any sense.
Even more odd - if I switch to an instance of Foo_Accessor() instead, the error goes away. I've played with the references and then I can eventually fix the above error - but then I get the same error for my Foo_Accessor() class!
I clean, rebuild, and sometimes the error will go away - but then I get the error 'Foo_Accessor' is not defined. Now I go to the Foo class and do 'create accessor' again - again, it still gives the same error. So at this point I'm stuck and my solution won't compile, and the only thing I did was add a new test case through visual studio!
Has anyone seen these issues and could please help?
Also - I have tried everything, including instructions from MS such as - renaming the type, re-referencing the project / in different ways, unloading the projects, etc, etc.. still I wind up with either the 'ifoo cannot convert to ifoo' bug or Foo_Accessor is not defined bug... I'm about to just break down and give the damned property I have to check a ReadOnly accessor... !
It's hard to say for certain but it sounds like you have a problem with your references being setup incorrectly. What's likely happening here is that one of the references between your projects is setup as a DLL reference vs. a project reference. This can confuse the type system into thinking that Bang from the project and Bang from the DLL are actually different types.
I would delete all references between my projects. Then go add all of them back again being careful to select the project from the project tab of the add reference dialog vs. the Browse one. This should fix your problem.
Is this a multi-language project or just a single language project? I've found this type of problem is more likely to occur in a multi-language project but it's certainly happened in a single language one.

Resources