diff --git a/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs b/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs index d207641584..54f176beac 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs @@ -556,19 +556,11 @@ internal static class DiaSourceObject public static IDiaDataSource GetDiaSourceObject() { - var currentDirectory = new ProcessHelper().GetCurrentProcessLocation(); + var nativeDllDirectory = new ProcessHelper().GetNativeDllDirectory(); - IntPtr modHandle = IntPtr.Zero; - if (IntPtr.Size == 8) - { - modHandle = LoadLibraryEx(Path.Combine(currentDirectory, "x64\\msdia140.dll"), IntPtr.Zero, 0); - } - else - { - modHandle = LoadLibraryEx(Path.Combine(currentDirectory, "x86\\msdia140.dll"), IntPtr.Zero, 0); - } + IntPtr modHandle = LoadLibraryEx(Path.Combine(nativeDllDirectory, "msdia140.dll"), IntPtr.Zero, 0); - if(modHandle == IntPtr.Zero) + if (modHandle == IntPtr.Zero) { throw new COMException(string.Format(Resources.Resources.FailedToLoadMsDia)); } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs index e463046c8e..eca17c7099 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/Interfaces/System/IProcessHelper.cs @@ -41,6 +41,18 @@ public interface IProcessHelper /// Location of test engine. string GetTestEngineDirectory(); + /// + /// Gets the location of native dll's, depending on current process architecture.. + /// + /// Location of native dll's + string GetNativeDllDirectory(); + + /// + /// Gets current process architecture + /// + /// Process Architecture + PlatformArchitecture GetCurrentProcessArchitecture(); + /// /// Gets the process id of test engine. /// diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs index aa147a1aad..feaaa76502 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs @@ -16,6 +16,8 @@ namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions /// public partial class ProcessHelper : IProcessHelper { + private static readonly string ARM = "arm"; + /// public object LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary envVariables, Action errorCallback, Action exitCallBack) { @@ -162,5 +164,23 @@ public int GetProcessId(object process) var proc = process as Process; return proc?.Id ?? -1; } + + /// + public PlatformArchitecture GetCurrentProcessArchitecture() + { + if (IntPtr.Size == 8) + { + return PlatformArchitecture.X64; + } + + return PlatformArchitecture.X86; + } + + /// + public string GetNativeDllDirectory() + { + var isArm = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").Contains("ARM"); + return Path.Combine(this.GetCurrentProcessLocation(), this.GetCurrentProcessArchitecture().ToString(), isArm ? ARM : string.Empty); + } } } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs index 6cd58c1706..7cd2ca470c 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/netstandard1.0/System/ProcessHelper.cs @@ -78,5 +78,17 @@ public int GetProcessId(object process) { throw new NotImplementedException(); } + + /// + public string GetNativeDllDirectory() + { + throw new NotImplementedException(); + } + + /// + public PlatformArchitecture GetCurrentProcessArchitecture() + { + throw new NotImplementedException(); + } } } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs index 1661246052..69525fa74a 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/uap10.0/System/ProcessHelper.cs @@ -77,5 +77,23 @@ public int GetProcessId(object process) { return -1; } + + /// + public PlatformArchitecture GetCurrentProcessArchitecture() + { + if (IntPtr.Size == 8) + { + return PlatformArchitecture.X64; + } + + return PlatformArchitecture.X86; + } + + /// + public string GetNativeDllDirectory() + { + // For UWP the native dll's are to be kept in same directory + return this.GetCurrentProcessLocation(); + } } }