Skip to content

Commit

Permalink
Fixed StackOverflowException when resolving Assemblies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haplois committed Nov 7, 2020
1 parent 4b8af65 commit 423f681
Show file tree
Hide file tree
Showing 31 changed files with 100 additions and 75 deletions.
1 change: 1 addition & 0 deletions TestFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "targets", "targets", "{F60B
ProjectSection(SolutionItems) = preProject
scripts\build\TestFx.Loc.targets = scripts\build\TestFx.Loc.targets
scripts\build\TestFx.Settings.targets = scripts\build\TestFx.Settings.targets
scripts\build\TestFx.Versions.targets = scripts\build\TestFx.Versions.targets
scripts\build\TestFx.targets = scripts\build\TestFx.targets
EndProjectSection
EndProject
Expand Down
6 changes: 3 additions & 3 deletions scripts/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ function Replace-InFile($File, $RegEx, $ReplaceWith) {
function Sync-PackageVersions {
$versionsFile = "$PSScriptRoot\build\TestFx.Versions.targets"

$versionsRegex = '(?mi)<(TestPlatfromVersion.*?)>(.*?)<\/TestPlatfromVersion>'
$versionsRegex = '(?mi)<(TestPlatformVersion.*?)>(.*?)<\/TestPlatformVersion>'
$packageRegex = '(?mi)<package id="Microsoft\.TestPlatform([0-9a-z.]+)?" version="([0-9a-z.-]*)"'
$sourceRegex = '(?mi)(.+[a-z =]+\@\")Microsoft\.TestPlatform\.([0-9.-a-z]+)\";'

if ([String]::IsNullOrWhiteSpace($TestPlatformVersion)) {
$TestPlatformVersion = (([XML](Get-Content $versionsFile)).Project.PropertyGroup.TestPlatfromVersion).InnerText
$TestPlatformVersion = (([XML](Get-Content $versionsFile)).Project.PropertyGroup.TestPlatformVersion).InnerText
} else {
Replace-InFile -File $versionsFile -RegEx $versionsRegex -ReplaceWith "<`$1>$TestPlatformVersion</TestPlatfromVersion>"
Replace-InFile -File $versionsFile -RegEx $versionsRegex -ReplaceWith "<`$1>$TestPlatformVersion</TestPlatformVersion>"
}

(Get-ChildItem "$PSScriptRoot\..\src\*packages.config","$PSScriptRoot\..\test\*packages.config" -Recurse) | ForEach-Object {
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/TestFx.Versions.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestPlatfromVersion Condition=" '$(TestPlatfromVersion)' == '' ">16.9.0-preview-20201102-05</TestPlatfromVersion>
<TestPlatformVersion Condition=" '$(TestPlatformVersion)' == '' ">16.9.0-preview-20201107-01</TestPlatformVersion>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@

<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Concurrent">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\System.Collections.Concurrent.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/MSTest.CoreAdapter/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MicroBuild.Core" version="0.2.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201102-05" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201107-01" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="StyleCop.Analyzers" version="1.0.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" />
<package id="System.Collections" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="System.ComponentModel" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
Expand Down
14 changes: 12 additions & 2 deletions src/Adapter/PlatformServices.Desktop/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security;
using System.Security.Permissions;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

/// <summary>
Expand All @@ -28,7 +29,16 @@ public class AssemblyResolver : MarshalByRefObject, IDisposable
/// The reason we have this is because the AssemblyResolver itself logs information during resolution.
/// If the resolver is called for the assembly containing the logger APIs, we do not log so as to prevent a stack overflow.
/// </remarks>
private const string LoggerAssemblyName = "Microsoft.VisualStudio.TestPlatform.ObjectModel";
private const string LoggerAssemblyNameLegacy = "Microsoft.VisualStudio.TestPlatform.ObjectModel";

/// <summary>
/// The assembly name of the dll containing logger APIs(EqtTrace) from the TestPlatform.
/// </summary>
/// <remarks>
/// The reason we have this is because the AssemblyResolver itself logs information during resolution.
/// If the resolver is called for the assembly containing the logger APIs, we do not log so as to prevent a stack overflow.
/// </remarks>
private const string LoggerAssemblyName = "Microsoft.TestPlatform.CoreUtilities";

/// <summary>
/// This will have the list of all directories read from runsettings.
Expand Down Expand Up @@ -577,7 +587,7 @@ private bool TryLoadFromCache(string assemblyName, bool isReflectionOnly, out As
/// <param name="loggerAction">The logger function.</param>
private void SafeLog(string assemblyName, Action loggerAction)
{
if (!string.IsNullOrEmpty(assemblyName) && !assemblyName.StartsWith(LoggerAssemblyName))
if (!string.IsNullOrEmpty(assemblyName) && !assemblyName.StartsWith(LoggerAssemblyName) && !assemblyName.StartsWith(LoggerAssemblyNameLegacy))
{
loggerAction.Invoke();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net45\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\net45\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net45\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\net45\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net45\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\net45\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="NuGet.Frameworks, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\NuGet.Frameworks.5.0.0\lib\net40\NuGet.Frameworks.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/PlatformServices.Desktop/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MicroBuild.Core" version="0.2.0" targetFramework="net451" developmentDependency="true" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201102-05" targetFramework="net45" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201107-01" targetFramework="net45" />
<package id="NuGet.Frameworks" version="5.0.0" targetFramework="net45" />
<package id="StyleCop.Analyzers" version="1.0.0" targetFramework="net45" developmentDependency="true" />
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ComponentModel.Primitives.4.3.0\lib\netstandard1.0\System.ComponentModel.Primitives.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/PlatformServices.Interface/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MicroBuild.Core" version="0.2.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201102-05" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201107-01" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="StyleCop.Analyzers" version="1.0.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" />
<package id="System.Collections" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="System.ComponentModel" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="$(TestPlatfromVersion)" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="$(TestPlatformVersion)" />
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\netstandard1.0\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ComponentModel.Primitives.4.3.0\lib\netstandard1.0\System.ComponentModel.Primitives.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/PlatformServices.Portable/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MicroBuild.Core" version="0.2.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201102-05" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201107-01" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="StyleCop.Analyzers" version="1.0.0" targetFramework="portable45-net45+win8+wp8+wpa81" developmentDependency="true" />
<package id="System.Collections" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="System.ComponentModel" version="4.3.0" targetFramework="portable45-net45+win8+wp8+wpa81" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
<HintPath>..\..\..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net451\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\net451\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net451\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\net451\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatfromVersion)\lib\net451\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.TestPlatform.ObjectModel.$(TestPlatformVersion)\lib\net451\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.8.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Moq.4.8.2\lib\net45\Moq.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.2.1" targetFramework="net451" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201102-05" targetFramework="net451" />
<package id="Microsoft.TestPlatform.ObjectModel" version="16.9.0-preview-20201107-01" targetFramework="net451" />
<package id="Moq" version="4.8.2" targetFramework="net451" />
<package id="NuGet.Frameworks" version="5.0.0" targetFramework="net451" />
<package id="StyleCop.Analyzers" version="1.0.0" targetFramework="net451" developmentDependency="true" />
Expand Down
Loading

0 comments on commit 423f681

Please sign in to comment.