From 1afdf846cbc60c0a6547f050d798089102f095ce Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 7 Apr 2016 09:30:54 -0700 Subject: make gRPC C# nuget work with new project.json style projects --- src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs') 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")] -- cgit v1.2.3