aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2016-04-07 09:30:54 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2016-04-07 09:36:12 -0700
commit1afdf846cbc60c0a6547f050d798089102f095ce (patch)
tree436fb04984c9d1970a5b1f87150b736ddf6ba820 /src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
parent041e39d713a415de82d92fe4f1ab102b7b0b2ffb (diff)
make gRPC C# nuget work with new project.json style projects
Diffstat (limited to 'src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs')
-rw-r--r--src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
index 47308f8c9e..5a80746101 100644
--- a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
+++ b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
@@ -32,8 +32,6 @@
#endregion
using System;
-using System.Collections.Concurrent;
-using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
@@ -63,14 +61,9 @@ namespace Grpc.Core.Internal
readonly string libraryPath;
readonly IntPtr handle;
- public UnmanagedLibrary(string libraryPath)
+ public UnmanagedLibrary(string[] libraryPathAlternatives)
{
- this.libraryPath = GrpcPreconditions.CheckNotNull(libraryPath);
-
- if (!File.Exists(this.libraryPath))
- {
- throw new FileNotFoundException("Error loading native library. File does not exist.", this.libraryPath);
- }
+ this.libraryPath = FirstValidLibraryPath(libraryPathAlternatives);
Logger.Debug("Attempting to load native library \"{0}\"", this.libraryPath);
@@ -139,6 +132,19 @@ namespace Grpc.Core.Internal
throw new InvalidOperationException("Unsupported platform.");
}
+ private static string FirstValidLibraryPath(string[] libraryPathAlternatives)
+ {
+ GrpcPreconditions.CheckArgument(libraryPathAlternatives.Length > 0, "libraryPathAlternatives cannot be empty.");
+ foreach (var path in libraryPathAlternatives)
+ {
+ if (File.Exists(path))
+ {
+ return path;
+ }
+ }
+ throw new FileNotFoundException(String.Format("Error loading native library. Not found in any of the possible locations {0}", libraryPathAlternatives));
+ }
+
private static class Windows
{
[DllImport("kernel32.dll")]