Skip to content

Loading native dll's correctly for UWP release mode #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/Microsoft.TestPlatform.ObjectModel/Navigation/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public interface IProcessHelper
/// <returns>Location of test engine.</returns>
string GetTestEngineDirectory();

/// <summary>
/// Gets the location of native dll's, depending on current process architecture..
/// </summary>
/// <returns>Location of native dll's</returns>
string GetNativeDllDirectory();

/// <summary>
/// Gets current process architecture
/// </summary>
/// <returns>Process Architecture</returns>
PlatformArchitecture GetCurrentProcessArchitecture();

/// <summary>
/// Gets the process id of test engine.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Microsoft.VisualStudio.TestPlatform.PlatformAbstractions
/// </summary>
public partial class ProcessHelper : IProcessHelper
{
private static readonly string ARM = "arm";

/// <inheritdoc/>
public object LaunchProcess(string processPath, string arguments, string workingDirectory, IDictionary<string, string> envVariables, Action<object, string> errorCallback, Action<object> exitCallBack)
{
Expand Down Expand Up @@ -162,5 +164,23 @@ public int GetProcessId(object process)
var proc = process as Process;
return proc?.Id ?? -1;
}

/// <inheritdoc/>
public PlatformArchitecture GetCurrentProcessArchitecture()
{
if (IntPtr.Size == 8)
{
return PlatformArchitecture.X64;
}

return PlatformArchitecture.X86;
}

/// <inheritdoc/>
public string GetNativeDllDirectory()
{
var isArm = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").Contains("ARM");
return Path.Combine(this.GetCurrentProcessLocation(), this.GetCurrentProcessArchitecture().ToString(), isArm ? ARM : string.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,17 @@ public int GetProcessId(object process)
{
throw new NotImplementedException();
}

/// <inheritdoc/>
public string GetNativeDllDirectory()
{
throw new NotImplementedException();
}

/// <inheritdoc/>
public PlatformArchitecture GetCurrentProcessArchitecture()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,23 @@ public int GetProcessId(object process)
{
return -1;
}

/// <inheritdoc/>
public PlatformArchitecture GetCurrentProcessArchitecture()
{
if (IntPtr.Size == 8)
{
return PlatformArchitecture.X64;
}

return PlatformArchitecture.X86;
}

/// <inheritdoc/>
public string GetNativeDllDirectory()
{
// For UWP the native dll's are to be kept in same directory
return this.GetCurrentProcessLocation();
}
}
}