Monday, December 5, 2011

MSTEST - UTA004: Illegal use of attribute on testmethod

Have you seem this error UTA004: Illegal use of attribute on testmethod. The TestMethodAttribute can be defined only inside a class marked with the TestClass attribute. while trying to run a mstest unit test.
The common scenario when this occurs is if there is a method with [TestMethod] attribute but the class in which it is defined does not have [TestClass] attribute.
However, even if you add the [TestClass] attribute and the error does not go away, the reason is that the class is not public.

Hence, make sure that the class is public and it has [TestClass] attribute.

Wednesday, November 23, 2011

Running SQLCMD Database Deployment scripts from SQL Management Studio

This is a very common scenario for database projects created in Visual Studio:
  • Create a database project
  • Right click the project and select Properties
  • Set "Deploy action" to "Create a deployment script (.sql)
  • Right click the project and select Deploy
This will generate the .sql file which can be used for deploying the database separately.

However, if you try to run this file from SQL Management Studio, it will result in errors.

This is because the script contains some sqlcmdvars (:setvar) which are specific to SQLCMD. If you run the same script using sqlcmd.exe, it would work fine.
If you want to run it from SQL Management Studio, click Query->SQLCMD Mode and then execute the query.

Tuesday, October 25, 2011

TFS 2010 Gated Checkin - Reconcile workspace after reboot

Normally when you checkin your changes with Gated Checkin enabled, once the files are checked in you see a "Team Foundation Build Notification" pop up to reconcile the workspace.
However, condiser you checkin something at the end of the day and go home thinking that you will reconcile the next day. In the mean time, your system got rebooted or went outside of network. The next day when you login to your system, you dont see the "Team Foundation Build Notification" pop up to reconcile the workspace.
You dont have to wait for the pop-up and can do the following:
  • Open the Build result of your Gated Checkin by double clicking on the Gated Checkin Build Definition in Team Explorer->Team Project->Builds
  • Click Reconcile Workspace


Thursday, October 20, 2011

TFS 2010 - Lab Build Definition appends the configuration to build output path $(BuildLocation)

Consider you have two build definitions:
  • DailyBuild - Uses DefaultTemplate.xaml
  • CIBuild - Uses LabDefaultTemplate.xaml
If you do not specify any configurations explicitly in DailyBuild, the CIBuild would work fine and you will be able to run the Build-Deploy-Test workflow smoothly.

However, as soon as you explicitly specify a configuration in DailyBuild, the CIBuild would start failing because it wont be able to find the binaries in the build drop.
This is because it appends the configuration to build output path in $(BuildLocation)

The solution is to modify the LabDefaultTemplate.xaml
Before:
<If Condition="[LabWorkflowParameters.BuildDetails.IsTeamSystemBuild = True]" DisplayName="Compute build location needed" sap:VirtualizedContainerService.HintSize="858,201">
       <If.Then>
         <Assign DisplayName="Compute build path" sap:VirtualizedContainerService.HintSize="291,100">
           <Assign.To>
             <OutArgument x:TypeArguments="x:String">[BuildLocation]</OutArgument>
           </Assign.To>
           <Assign.Value>
             <InArgument x:TypeArguments="x:String">[If(LabWorkflowParameters.BuildDetails.Configuration Is Nothing, BuildLocation, If(LabWorkflowParameters.BuildDetails.Configuration.IsEmpty Or (SelectedBuildDetail.Information.GetNodesByType(Microsoft.TeamFoundation.Build.Common.InformationTypes.ConfigurationSummary, True)).Count = 1, BuildLocation, If(LabWorkflowParameters.BuildDetails.Configuration.IsPlatformEmptyOrAnyCpu, BuildLocation + "\" + LabWorkflowParameters.BuildDetails.Configuration.Configuration, BuildLocation + "\" + LabWorkflowParameters.BuildDetails.Configuration.Platform + "\" + LabWorkflowParameters.BuildDetails.Configuration.Configuration)))]</InArgument>
           </Assign.Value>
         </Assign>
       </If.Then>
     </If>
 After:
 <If Condition="[LabWorkflowParameters.BuildDetails.IsTeamSystemBuild = True]" DisplayName="Compute build location needed" sap:VirtualizedContainerService.HintSize="858,201">
       <If.Then>
         <Assign DisplayName="Compute build path" sap:VirtualizedContainerService.HintSize="291,100">
           <Assign.To>
             <OutArgument x:TypeArguments="x:String">[BuildLocation]</OutArgument>
           </Assign.To>
           <Assign.Value>
             <InArgument x:TypeArguments="x:String">[BuildLocation]</InArgument>
           </Assign.Value>
         </Assign>
       </If.Then>
     </If>

Wednesday, October 12, 2011

SQLCMD - QUOTED_IDENTIFIER is OFF

If you want to deploy the Differential script on a Database in an automated way, the most common way is to use SQLCMD. For example:

sqlcmd -S Server-d Database1 -U UserName -P Password -i DatabaseBuild-ProdDiff.sql

However, when you run this script, QUOTED_IDENTIFIER is set to OFF

When running the stored procedures, you might see errors like:
Message: UPDATE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'.

The reason for this is that QUOTED_IDENTIFIER is not set to ON
To set it to ON, you should pass the -I argument, For example:
sqlcmd -I -S Server-d Database1 -U UserName -P Password -i DatabaseBuild-ProdDiff.sql

Thursday, September 29, 2011

Windows Azure Tools 1.4 - Error: Certificate: ‘CertName’ with Thumbprint: xxx for Role: RoleName has not been uploaded to the hosted service: ServiceName.

Consider your Windows Azure role has a configuation like:

<Certificates>
  <Certificate name="CertName" thumbprint="xxx" thumbprintAlgorithm="sha1" />
</Certificates>

When you try to deploy to cloud from Visual Studio by right clicking the Windows Azure project and selecting Publish, you might see a log like this:
5:20:37 PM - Preparing...
5:20:37 PM - Connecting...
5:20:38 PM - Error: Certificate: ‘CertName’ with Thumbprint: xxx for Role: RoleName has not been uploaded to the hosted service: ServiceName.


The reason for this error could be that the Certificate Thumbprint which is displayed on the Windows Azure Portal is in UpperCase and the one specified in your configuration is in LowerCase or vice versa.

The fix for this is to copy the Thumbprint from Windows Azure Portal  and paste it in your configuration so that the case match at both places.

Friday, September 23, 2011

TFS 2010 - There was no endpoint listening at http://buildagent:9191/Build/v3.0/Services/Controller/1 that could accept the message

Sometimes the build agent stops working all of a sudden and you see the error:
There was no endpoint listening at http://buildagent:9191/Build/v3.0/Services/Controller/1 that could accept the message

This could occur because of incorrect proxy being set. If you uncheck the below checkbox or correct the proxy, it should fix the issue.

















The other fix for this is to unregister the Build Services and Register it again. Below are the steps:
  • Open Team Foundation Administration console
  • Go to Build Configuration
  • Click "Unregister" link on the build service
  • Click "Register" link on the build service
  • Specify the "Team Project Collection" and "Credentials" and Save

Monday, September 12, 2011

TFS 2010 Lab Management - There are no test cases matching the criteria specified

Have you seen the below error while running the Build-Deploy-Test worklow using Lab Managemnt in TFS 2010. "There are no test cases matching the criteria specified. Use Microsoft Test Manager to view the test cases."

Following are the possible causes for this error:
  • You are not building the test projects in the Build. Hence the test binaries are missing in TestDirectory.
  • You have not selected the correct Test Plan or Test Suite in the Test section of the Lab Build Definition which has the automated test cases .
  • The Test Confirugation selected in the Test section of the Lab Build Definition does not match the Configuration selected for the automated test case in Microsoft Test Manager.

Monday, August 29, 2011

VS 2010 Load Test - The ConnectionString property has not been initialized

Have you seen the below error while running a load test in VS 2010
---------------------------
Microsoft Visual Studio
---------------------------
Could not read result repository: The ConnectionString property has not been initialized..


Will display the runtime result instead of the repository result.
---------------------------
OK
---------------------------

 The reason is that you have selected "None" in the "Storage Type" property of the Run Settings. Instead select "Database" and you should not see this error.

Tuesday, August 23, 2011

TFS 2010 - The process cannot access the file 'data.coverage' because it is being used by another process

Have you came across a situation where your build is running indefinitely and when you see stop the build, the following error is thrown:

The process cannot access the file 'data.coverage' because it is being used by another process.

This happens only when code coverage is enabled in the testsettings being used in the build. Also, you will see this issue if one of your unit tests is having an issue. To know about the root cause of the issue with the unit test, you can do the following:
  • Go to the build agent box
  • Browse to the directory where the build agent "Sources", "Binaries" and "Test Results" folder are present
  • Open the trx file in the "Test Results" folder
  • Click on "Test run error"
You will see the exact cause of the issue here.

Also, if you dont want to Stop the build forcefully and allow it to finish the execution, please follow these steps:
  • Go to the build agent box
  • Go to Task Manager and kill the process "VSPerfMon.exe"
This will allow the build to complete gracefully but you will not see any unit test and code coverage results.

Thursday, August 18, 2011

ACS50016 Error- Windows Azure AppFabric Access Control Service

If you think you have configured the service identity correctly in ACS and have the right client certificates but still get below error, the cause is that your certificate format is not correct.
ACS50016: X509Certificate with subject 'CN=...' and thumbprint '...' does not match any certificates configured for Service identities

You should upload a .cer file with DER format for the service identity. If you uploaded a Base-64 format, it wont wont.

Friday, July 15, 2011

Microsoft Test Manager - Update Test Settings

Here is a great source for updating the test settings in MTM http://blogs.msdn.com/b/aseemb/archive/2010/08/06/update-testsettings-utility.aspx

You can override public properties like Deployment Timeout using this.

You can also override the private properties like Script Timeout using Reflection. Please refer this thread for more info http://social.msdn.microsoft.com/Forums/en-US/vsmantest/thread/5a6f3af4-9e28-42d9-8830-f800969d8b28/

Tuesday, July 12, 2011

TFS 2010 - Build fails with error " Read permission is required to retrieve the content"

When the build fails with the below error, what does it mean:
TF215097: An error occurred while initializing a build for build definition \TeamProject\BuildDef: TF204001: The item $/TeamProject/BuildProcessTemplates/DefaultTemplate.xaml cannot be downloaded. Read permission is required to retrieve the content.
It means that the service account under which the build agent is running needs read access to the source control.

Saturday, July 2, 2011

Received 2011 Microsoft® MVP Award!

I received an email from Microsoft that I have been awarded the 2011 Microsoft® MVP Award for my contributions in Visual Studio ALM technical communities during the past year. It is a pleasure to receive this award and I am very grateful to Microsoft.

Here is the link to my profile https://mvp.support.microsoft.com/default.aspx/profile=22555aef-9708-47fd-a2f1-bc660de3ebcd

Sunday, June 19, 2011

TFS 2010 - Unable to stop build

I came across an issue where a build was stuck for days with the message:
There was no endpoint listening at http://machinename:9191/Build/v3.0/Services/Agent/282 that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

When I tried to stop the build, I was shown the error:
TF215104: Failed to stop build: it did not respond to a workflow cancellation request." When I went to the build agent and tried to delete the agent, I was shown the error:
Cannot remove build agent from build controller because it is currently reserved for a build

I unregistered the build service, tried to stop the build, registered the build service again and kept repeating the steps multiple times. I finally had luck and the build was stopped.
I registered the build service again and everything was smooth.

If you have write access to the TFS Warehouse, you can delete the build agent by following the steps at http://sleepcanwait.blogspot.com/2010/07/cannot-remove-build-agent-from-build.html 

Saturday, June 18, 2011

TFS 2010 Test Controller - Disk runs out of space

You must have observed that the disk on test controller runs out of space pretty fast. This is because of the files being stored in localappdata%\VSEQT\QTController\TestRunStorage which never get deleted. There are two options:

Option1:
Add a key ControllerJobSpooling in \Microsoft Visual Studio 10.0\Common7\IDE\QTController.exe.config and set its value to false. Then restart the test controller service.
Also refer http://blogs.msdn.com/b/shivash/archive/2011/01/21/using-visual-studio-test-controller-with-mtm-and-disk-out-of-space-issues.aspx

Option2:
Create a batch file with this command:
rmdir /s /q "C:\Users\<serviceaccount>\AppData\Local\VSEQT\QTController"
Then create a scheduled task which calls this batch file at regular intervals.

VS 2010 TestSettings - Ignore Dependent Assemblies

The testsettings in VS2010 tries to copy the dependent assemblies to the test output directory by default.
However, there might be situations where you would not want to copy the dependent assemblies. These dependent assemblies can be ignored by using the attribute ignoredDependentAssemblies

The below example shows how to ignore the dependent assemblies A, B and C and also to add a deployment item a.csv. You will need to restart Visual Studio after making this change.

<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="46d8e12e-16c0-4ba4-9dd9-eda66fb2ccc6" xmlns="
http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Description>These are default test settings for a local test run.</Description>
  <Deployment ignoredDependentAssemblies="(?i:^A|^B|^C)">
    <DeploymentItem filename="TestProjectA\a.csv"/>
  </Deployment>
  .....

Thursday, June 16, 2011

How to Kill open connections to a Database

I came across a scenario when I wanted to restore a Database. However I was getting an error saying the databse is already in use. I needed to find who was connected to the databse and kill that connection.
So I first ran the command exec sp_who
This gave me the spid of the connection.
Then I ran the commad kill _spid to kill this connection.

Saturday, June 11, 2011

Why is Debugging in VS slow and takes forever saying "Loading Symbols..."

I encountered an issue in one of my Win 2K8 server machine where debugging a simple application in Visual Studio was taking forever. Everything was fine if you run the application but as soon as you tried debugging it, the performance was really slow and it took forever saying "Loading Symbols..."

When I went to Tool->Options->Debugging->Symbols, I found that it was referring to an environment variable _NT_SYMBOL_PATH whose value was some url which wasn't reachable.

I deleted this environment variable from My Computer->Properties->Advanced System Settings->Advanced->Environment Variables... and everything was fine after that. I was able to debug the application without any issues.

Monday, May 23, 2011

TFS 2010 - Associate existing test cases with test methods

If you want to create new test cases which are associated with test methods, tcm.exe will solve your purpose.
However, what if you want to associate existing test cases with test methods.
Here is the thread on MSDN forum which poinst out how to associate existing test cases with test methods http://social.msdn.microsoft.com/Forums/en-US/vsmantest/thread/774642af-fa44-473d-ab6d-817cfa83cf10/

Saturday, April 30, 2011

VS 2010 - Different Timeouts in Testsettings file

The following are the different types of timeouts that can be configured in testsettings file:
  • agentNotRespondingTimeout
  • deploymentTimeout
  • runTimeout
  • scriptTimeout
  • testTimeout
Setting these timeouts are not very obvious when the testsetting is opened with 'Test Settings Editor'. Hence, open the testsettings file in 'XML (text) Editor'

You can then add various timeouts in milliseconds in the Timeouts node under the Execution node.
<TestSettings name="Local" id="46d8e12e-16c0-4ba4-9dd9-eda66fb2ccc6" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
   <Description>These are default test settings for a local test run.</Description>
   <Execution>
     <Timeouts agentNotRespondingTimeout="1800000" deploymentTimeout="" runTimeout="1800000" scriptTimeout="1800000" testTimeout="1800000"/>

Monday, April 18, 2011

VS 2010 - Create Load Test Repository

One day I found that my Load Test Reporsitory is missing and hence I was not able to run the load tests.
The load tests were failing with the error:
---------------------------
Microsoft Visual Studio
---------------------------
Error occurred running test. The load test results database could not be opened.  Check that the load test results database specified by the connect string for your test controller (or local machine) specifies a database that contains the load test schema and that is currently available.  For more information, see the Visual Studio help topic 'About the Load Test Results Store'.   The connection error was: An error occurred while attempting to create the load test results repository schema: Cannot find the object 'LoadTestTestCaseSummary', because it does not exist or you do not have permission.
---------------------------
OK  
---------------------------

To resolve this issue, I followed the below steps:
1) Open VS command prompt in elevated mode (Run As Administrator)
2) Run the command "cd C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE"
3) Run the command "SQLCMD /S localhost\sqlexpress /i loadtestresultsrepository.sql "

Sunday, March 27, 2011

TFS 2010 - hexadecimal value 0x07 is an invalid character

I recently encountered an issue where my tests in lab management were getting aborted. I really had a hard time figuring out what was really going wrong. I looked into the test run log in the Test Manager->Analyze Test Runs but nothing obvious showed up. I also enabled diagnostic logging in my lab build definition but again nothing showed up.
I then used tcm.exe and created a new test run using "tcm run /create". Then I executed the run using "tcm run /execute" and I got the error: "hexadecimal value 0x07 is an invalid character"
Then I looked into the intellitrace logs in "%localappdata%"\VSEQT\QTController. Here I found that there was an invalid xml in my Assert statement.
Fixing the xml in the Assert solved my problem.

Why http://localhost does not work?

I encountered an issue recently where I was able to browse the Default Web Site using http://IPAddress but was not able to browse it using http://localhost
The reason for that was the Default Web Site Bindings.
If you click on Default Web Site, then click Bindings on the Actions pane, you will see the Site Bindings. Edit the Bindings and in the IP Address drop down, select "All Unassigned" instead of a specific IP Address.

Tuesday, March 8, 2011

TFS 2010 Build: Keep folder tree structure

There are two approaches :
=============================================
Approach 1
=============================================

To keep the output structure, you have to make TFSBuildHost not pass OutDir
to MSBuild and  custom the output path of each project.
  1. Open the build process file, navigate to Compile the Project Sequence, edit the property of Run MSBuild for Project Activity.
    • Set OutDir to empty (just make the textbox is empty)
    • set CommandLineArguments to String.Format("/p:SkipInvalidConfigurations=true {0} /p:TeamBuildOutDir=""{1}""", MSBuildArguments, outputDirectory)
  2. Modify each project file in the solution.
    • Check out project file to Edit.
    • Open project file  with notepad.
    • Find <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    • Use following code to replace the default OutputPath Property.
                   <OutputPath Condition=" '$(TeamBuildOutDir)'=='' ">bin\release\</OutputPath>
                   <OutputPath Condition=" '$(TeamBuildOUtDir)'!='' ">$(TeamBuildOutDir)\<ProjectName>\</OutputPath>
                  The word “Release|AnyCPU” is dependent on the value of “ConfigrationToBuild”  in   TFSBuild.proj.      
    • Save project file and check in.
=============================================
Approach 2
=============================================
  1. Open the build process file, navigate to Compile the Project Sequence, edit the property of Run MSBuild for Project Activity.
  2. Set OutDir to empty (just make the textbox is empty)
  3. Set OutDir to System.IO.Path.Combine(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(localProject))
  4. In the build definition, instead of specifying a single solution, specify the projects individually

Monday, March 7, 2011

TFS 2010 Deployment Items - Prefer DeploymentItem attribute

There are multiple ways to configure deployment items when working with TFS 2010. Lets have a look at them one by one.

Local.testsettings
You can specify the deployment items in the Deployment section of Local.testsettings
Visual studio by default picks up the testsettings while running the tests.
If you are using command line, then you will nedd to pass the /testsetting parameter to mstest
If you are running your tests as part of build process, you need to specify the Local.testsettings in the build definition.

Lab Manager TestSettings
If you are running the test as part of lab process, then the Visual Studio testsetting is not used. You will need to create a test setting in lab manager and the files that are specified should be present on the test controller or be under a shared location.
To use this testsetting, you will have to specify it as part of your test plan or lab build definition.

DeploymentItem Attribute
The best way to make your tests work under all circumstances without making any changes is to use the DeploymentItem attribute on your test class/method.
No matter how you are running your tests, the deployment items will always be copied to the test execution folder.

TFS 2010 TCM - Importing the test cases along with the Area and Iteration paths

With tcm.exe, you can import test cases from your test code. You can pass the test assembly to tcm and it will create new test cases or update existing test cases for each TestMethod. The command for importing the test cases is:

tcm testcase /import /collection:teamprojectcollectionurl /teamproject:project
             /storage:path
             [/maxpriority:priority]
             [/minpriority:priority]
             [/category:filter]
             [/syncsuite:id [/include]]
             [/login:username,[password]]

Also refer http://msdn.microsoft.com/en-us/library/ff942471.aspx

Consider a scenario where you created 10 TestMethods and use tcm to import the test cases. 10 new test cases are created in this case.
You realize that you need to update the Area property of these test cases. Hence you open them in excel and update the Area in one shot.
Now you add 5 more TestMethods and use tcm to import the test cases. 5 new test cases are created in this case. Howevere, along with creating new test cases, the older 10 test cases are updated and the Area property is reseted. So you have to again open all the test cases in excel and update the Area.

In order to make sure that your new test case get the Area assigned while they are imported and you dont loose the Area of exisitng test cases, you can add the following attribute to the TestMethods:
[CssProjectStructure("vstfs:///Classification/Node/<guid>")]
 You can find the guid from Tfs_Warehouse
select AreaGUID from DimArea where AreaPath='...'

Similarly, if you want to update the Iteration, you can use
[CssIteration("vstfs:///Classification/Node/<guid>")]
You can find the guid from Tfs_Warehouse
select IterationGUID from DimIteration where IterationPath='...'

Similarly, you could add other supported attributes to the TestMethods to make sure that they are imported.

TFS 2010 Test Controller - Workaround for TestRunStorage issue

When worked with Test Controller for lab management in TFS 2010, you might have experienced that you start running out of disk space soon. The reason for that is the test results keep accumulating at the path C:\Users\<Account>\AppData\Local\VSEQT\QTController\TestRunStorage

Even if you do the following in MTM (Lab Center -> Controllers -> Right click on controller -> Delete
temporary files), the files in TestRunStorage are not deleted.

To get around this issue, you can create a batch file with the following command:
rmdir /s /q "C:\Users\...\AppData\Local\VSEQT\QTController"

Then create a scheduled task which calls this batch file once every day at
a specific time when no tests would run.

TFS 2010 Build- Running unit tests with code coverage enabled on signed assemblies

For signed assemblies, running unit tests with code coverage enabled requires the key file (*.snk, *.pfx) to be specified in the "Code Coverage Detail" tab in the testsettings.

This works fine when you run the tests locally in Visual Stuio. The problem occurs when you try to use this testsettings in the TFS Build. The specified path of the key file is absolute rather than relative. Hence the key file isnt found during the build.

The solution to the problem is:
Suppose your solution directory is C:\TestSolution and your key file is present at C:\TestSolution\TestProject\Key.snk
Open the testsetting in notepad and instead of specifying the full key path, specify TestProject\Key.snk