Visual Studio 测试运行程序找不到测试并失败,并显示: 无法翻译部分或全部标识引用



我试图用.runsettings文件执行测试,但测试运行失败,并显示以下消息:

------ Run test started ------
Some or all identity references could not be translated.
Operation is not valid due to the current state of the object.
========== Run test finished: 0 run (0:00:00,2280287) ==========

EventLog提供了有关错误的更多详细信息:

Error Handler Exception: System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.
   at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
   at System.Security.Principal.NTAccount.Translate(Type targetType)
   at Microsoft.VisualStudio.Enterprise.WebInstrument.IISResetter.CreateSidFromUser(String userName)
   at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.GetUserFromAppPool(ApplicationPool pool)
   at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.get_Users()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.get_AllowedUsers()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.InitiateCollection()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.GetEnvironmentVariables()
   at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.GetEnvironmentVariables()
   at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.Microsoft.VisualStudio.TestTools.Execution.ITestExecutionEnvironmentSpecifier.GetTestExecutionEnvironmentVariables()
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.TestPlatformDataCollectorInfo.GetTestExecutionEnvironmentVariablesSync()
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.GetEnvironmentVariables(Boolean& unloadedAnyCollector)
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadAndInitDataCollectors(DataCollectionRunSettings dataCollectionSettings, Boolean& allCollectorsLoaded)
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadDataCollectors(RunSettings testRunSettings, Boolean& allCollectorsLoaded)
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.WcfTestRunnerService.BeforeTestRunStart(String settingsXml, Boolean resetDataCollectors, Boolean isRunStartingNow)
   at SyncInvokeBeforeTestRunStart(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) rn    at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
   at System.Security.Principal.NTAccount.Translate(Type targetType)
   at Microsoft.VisualStudio.Enterprise.WebInstrument.IISResetter.CreateSidFromUser(String userName)
   at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.GetUserFromAppPool(ApplicationPool pool)
   at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.get_Users()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.get_AllowedUsers()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.InitiateCollection()
   at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.GetEnvironmentVariables()
   at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.GetEnvironmentVariables()
   at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.Microsoft.VisualStudio.TestTools.Execution.ITestExecutionEnvironmentSpecifier.GetTestExecutionEnvironmentVariables()
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.TestPlatformDataCollectorInfo.GetTestExecutionEnvironmentVariablesSync()
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.GetEnvironmentVariables(Boolean& unloadedAnyCollector)
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadAndInitDataCollectors(DataCollectionRunSettings dataCollectionSettings, Boolean& allCollectorsLoaded)
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadDataCollectors(RunSettings testRunSettings, Boolean& allCollectorsLoaded)
   at Microsoft.VisualStudio.TestPlatform.TestRunnerService.WcfTestRunnerService.BeforeTestRunStart(String settingsXml, Boolean resetDataCollectors, Boolean isRunStartingNow)
   at SyncInvokeBeforeTestRunStart(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

删除.runsettings文件可以修复此问题,但在覆盖率报告中包含了一些我们要排除的程序集。

事实证明,当您包含这样一个文件时,ASP.NET代码覆盖率集合就会激活。这反过来需要重置应用程序池以将其自身连接到应用程序池。(因此引用了IIS7Resetter)。关闭ASP.NET代码覆盖率收集功能可解决错误:

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>
<!-- Include the below line in your .runsettings file-->
            <CollectAspDotNet>False</CollectAspDotNet>
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

但这并不能解释出了什么问题。由于堆栈跟踪提示应用程序池用户,我们开始对此进行调查。事实证明,将应用程序池设置为LocalSystemNetworkService实际上也解决了这个问题。我们将其配置为.SomeLocalUser。更多的修补发现了根本原因,用于获取应用程序池标识的代码不喜欢短符号。实际上输入机器名称完全修复了它:MachineNameSomeLocaluser。我怀疑这是Visual studio中的一个实际错误,它将在未来的时间内得到修复,但在那之前,这两个选项可能也会帮助其他人找出问题所在。

注意:默认情况下,最好将CollectAspDotNet选项设置为False。只要您没有针对服务器运行集成测试或CodedUI测试,它就会大大加快测试运行速度。

另请参阅:

  • https://jessehouwing.net/visual-studio-vstest-fix-identity-references/
  • http://msdn.microsoft.com/en-us/library/jj159530%28v=vs.110%29.aspx

相关内容

  • 没有找到相关文章

最新更新