Search code examples
visual-studiotestingazure-devops

Error: Cannot register property 'TestType' as value type 'System.Guid' because it was already registered as 'System.String'


I updated the Visual Studio from 2019 to 2022 and started to get the following error when running unit tests (I'm using Google Test Adaptor (v 1.17.0.32) and Google Test framework for a C++ project):

##[error]An exception occurred while invoking executor 'executor://codedwebtestadapter/v1': The type initializer for 'Microsoft.VisualStudio.TestPlatform.Extensions.TmiHelper.Constants' threw an exception.
##[error]Stack trace:
##[error]   at Microsoft.VisualStudio.TestPlatform.Extensions.TmiHelper.TmiBridge..ctor()
##[error]   at Microsoft.VisualStudio.TestPlatform.Extensions.CodedWebTestAdapter.CodedWebTestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
##[error]   at Microsoft.VisualStudio.TestPlatform.Common.ExtensionDecorators.SerialTestRunDecorator.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle) in /_/src/Microsoft.TestPlatform.Common/ExtensionDecorators/SerialTestRunDecorator.cs:line 59
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithSources.cs:line 116
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.<>c__DisplayClass46_0.<RunTestInternalWithExecutors>b__0() in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs:line 464
##[error]   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.<>c__DisplayClass0_0.<Run>b__0() in /_/src/Microsoft.TestPlatform.PlatformAbstractions/net462/System/PlatformThread.cs:line 29
##[error]--- End of stack trace from previous location where exception was thrown ---
##[error]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
##[error]   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.Run(Action action, PlatformApartmentState apartmentState, Boolean waitForCompletion) in /_/src/Microsoft.TestPlatform.PlatformAbstractions/net462/System/PlatformThread.cs:line 47
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.TryToRunInStaThread(Action action, Boolean waitForCompletion) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs:line 680
##[error]   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs:line 464
##[error]
##[error]Inner exception: Cannot register property 'TestType' as value type 'System.Guid' because it was already registered as 'System.String'.
##[error]
##[error]Stack trace:
##[error]   at Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty.Register(String id, String label, String category, String description, Type valueType, ValidateValueCallback validateValueCallback, TestPropertyAttributes attributes, Type owner) in /_/src/Microsoft.TestPlatform.ObjectModel/TestProperty/TestProperty.cs:line 347
##[error]   at Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty.Register(String id, String label, Type valueType, TestPropertyAttributes attributes, Type owner) in /_/src/Microsoft.TestPlatform.ObjectModel/TestProperty/TestProperty.cs:line 304
##[error]   at Microsoft.VisualStudio.TestPlatform.Extensions.TmiHelper.Constants..cctor()

As you see above, the main part of the error is :

Cannot register property 'TestType' as value type 'System.Guid' because it was already registered as 'System.String'.

The error happens in the following Azure Pipeline task:

  - task: VSTest@2
    displayName: 'Run tests and coverage'
    inputs:
      testSelector: 'testAssemblies'
      testAssemblyVer2: |
        **\RunUnitTests.exe
      searchFolder: '$(Build.SourcesDirectory)/build/build.$(BuildSystem).$(BuildPlatform).multi'
      pathtoCustomTestAdapters: '$(GoogleTestAdapterPath)' # Test Adapter for Google Test (MSFT fork of Google Test Adapter, shipped with VS2019 and VS2022)
      codeCoverageEnabled: 'true'
      platform: '$(BuildPlatform)'
      configuration: '$(BuildConfiguration)'
      runSettingsFile: '$(Build.SourcesDirectory)\tools\ClientSDKTools\libmrh.runsettings'    
    condition: and(succeeded(), eq(variables['BuildPlatform'], 'x64'), eq(variables['BuildSystem'], 'Windows'))

I suspect there is some library mismatch/inconsistency in Test libraries.

Things I've tried:

  • I updated Micrososft.TestPlatform package via nuget --> "dotnet add package Microsoft.TestPlatform" for various projects in the repo but still got the same error.
  • I reverted to VSTest@1 Azure Pipeline task (instead of VSTest@2). Still got the same error.
  • I looked for TestType in the source code but did not find any occurance of that. As I suspected, the TestType should have been used in some internal MS libraries and not my code.

Solution

  • Cannot register property 'TestType' as value type 'System.Guid' because it was already registered as 'System.String'.

    This is a known issue in recent Visual Studio 2022 versions. Refer to this ticket: VS2022 17.10.1 throws an error in Azure DevOps pipelines (self hosted) with VSTest@2

    The issue is related to the changes made in google test few months ago. Here is the details: Fix parameterized test settings

    I have checked the internal resource and confirmed that the issue has been fixed in the Visual Studio 2022 version 17.12.

    Currently, Visual Studio 2022 17.12 is in the process of being released. We still need to wait for a while. You can keep monitoring the ticket above to check the update.

    When you using Azure DevOps Pipeline, I would like to share a workaround:

    You can use Visual Studio test platform installer task to roll back to old version of Visual Studio 2022 17.8. And set the vsTestVersion: 'toolsInstaller' in VStest task.

    steps:
    - task: VisualStudioTestPlatformInstaller@1
      inputs:
        packageFeedSelector: 'nugetOrg'
        versionSelector: 'specificVersion'
        testPlatformVersion: '17.8.0'
    - task: VSTest@2
      displayName: 'Run tests and coverage'
      inputs:
        testSelector: 'testAssemblies'
        vsTestVersion: 'toolsInstaller'
        testAssemblyVer2: |
          **\RunUnitTests.exe
        searchFolder: '$(Build.SourcesDirectory)/build/build.$(BuildSystem).$(BuildPlatform).multi'
        pathtoCustomTestAdapters: '$(GoogleTestAdapterPath)' # Test Adapter for Google Test (MSFT fork of Google Test Adapter, shipped with VS2019 and VS2022)
        codeCoverageEnabled: 'true'
        platform: '$(BuildPlatform)'
        configuration: '$(BuildConfiguration)'
        runSettingsFile: '$(Build.SourcesDirectory)\tools\ClientSDKTools\libmrh.runsettings'    
      condition: and(succeeded(), eq(variables['BuildPlatform'], 'x64'), eq(variables['BuildSystem'], 'Windows'))