mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-19 23:28:15 +08:00
ae7a29a9f1
Due to the way VS test works (by injecting an executable entry point), the performance tests needed to be factored out. I also organized all of our existing tests better along the way. Actual code changes to Dapper itself are very minor, only formatting and documentation fixes (which we need many more of). The build.ps1 script is upated to work, but note that <frameworkAssemblies> is not working in .nuspec inside the packages in the new .csproj system. I consider this to be a blocker. Issue is here: https://github.com/NuGet/Home/issues/4853
58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Dapper.Tests
|
|
{
|
|
/// <summary>
|
|
/// Utility methods related to CLR Types for SQL Server
|
|
/// </summary>
|
|
internal static class SqlServerTypesLoader
|
|
{
|
|
private static readonly object _nativeLoadLock = new object();
|
|
private static bool _nativeAssembliesLoaded;
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
private static extern IntPtr LoadLibrary(string libname);
|
|
|
|
/// <summary>
|
|
/// Loads the required native assemblies for the current architecture (x86 or x64)
|
|
/// </summary>
|
|
/// <param name="rootApplicationPath">
|
|
/// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
|
|
/// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
|
|
/// </param>
|
|
public static void LoadNativeAssemblies(string rootApplicationPath)
|
|
{
|
|
if (_nativeAssembliesLoaded)
|
|
return;
|
|
lock (_nativeLoadLock)
|
|
{
|
|
if (!_nativeAssembliesLoaded)
|
|
{
|
|
var nativeBinaryPath = IntPtr.Size > 4
|
|
? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
|
|
: Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");
|
|
|
|
LoadNativeAssembly(nativeBinaryPath, "msvcr100.dll");
|
|
LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial110.dll");
|
|
_nativeAssembliesLoaded = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
|
|
{
|
|
var path = Path.Combine(nativeBinaryPath, assemblyName);
|
|
var ptr = LoadLibrary(path);
|
|
if (ptr == IntPtr.Zero)
|
|
{
|
|
throw new Exception(string.Format(
|
|
"Error loading {0} (ErrorCode: {1})",
|
|
assemblyName,
|
|
Marshal.GetLastWin32Error()));
|
|
}
|
|
}
|
|
}
|
|
}
|