Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gRPC C#0.13.0用于webapplication时出现FileNotFound异常_C#_Grpc - Fatal编程技术网

gRPC C#0.13.0用于webapplication时出现FileNotFound异常

gRPC C#0.13.0用于webapplication时出现FileNotFound异常,c#,grpc,C#,Grpc,我将Web应用程序的gPRC版本从0.12.0更新为0.13.0,但它开始无法创建频道对象。以下是引发的异常: 它正试图在AppData\\Local\\Temp\\Temporary ASP.NET Files\\root\\c8490d1a\\9f150f28\\assembly\\dl3\\5d08d985\\2c1c8757\u 6474d101\\nativelibs\\windows\u x86\\grpc\u csharp\u ext.dll中定位。我甚至将DLL存储在本地bin

我将Web应用程序的gPRC版本从0.12.0更新为0.13.0,但它开始无法创建
频道
对象。以下是引发的异常:

它正试图在
AppData\\Local\\Temp\\Temporary ASP.NET Files\\root\\c8490d1a\\9f150f28\\assembly\\dl3\\5d08d985\\2c1c8757\u 6474d101\\nativelibs\\windows\u x86\\grpc\u csharp\u ext.dll中定位
。我甚至将DLL存储在本地
bin
文件夹中,但这没有帮助。如果创建控制台应用程序,则不会出现此问题。我不知道为什么它试图在所述位置搜索dll?有人知道如何让它为web应用程序工作吗

编辑此问题由GRPC社区根据修复。我也证实了这一点。现在我们需要将
grpc\u csharp\u ext.dll
保存在
bin\nativelibs\windows\u x86\
(对于32位dll)和
bin\nativelibs\windows\u x64\
(对于64位dll)

Asp.net在动态编译期间执行。它复制Grpc.Core.dll,但不复制包含本机Grpc_csharp_ext.dll文件的文件夹nativelibs。 我通过编程处理nativelibs文件夹解决了这个问题

从Global.asax中的应用程序_Start调用copy方法

public class WebApplication : HttpApplication
{
    protected void Application_Start()
    {
        GrpcInitializer.EnsureGrpcCSharpExtNativeDll();
    }
}
复印机:

public static class GrpcInitializer
{
    public static void EnsureGrpcCSharpExtNativeDll()
    {
        var grpcCoreAssembly = Assembly.GetAssembly(typeof(Grpc.Core.Channel));
        var srcFolderPath = Path.GetDirectoryName(new Uri(grpcCoreAssembly.CodeBase).LocalPath);

        CopyGrpcCSharpExtNativeDll(srcFolderPath);
    }

    public static void CopyGrpcCSharpExtNativeDll(string srcFolderPath)
    {
        var grpcCoreAssembly = Assembly.GetAssembly(typeof(Grpc.Core.Channel));
        var grpcDllLocation = Path.GetDirectoryName(grpcCoreAssembly.Location);
        if (grpcDllLocation == null)
            return;

        var targetFolderPath = Path.Combine(grpcDllLocation, "nativelibs");
        if (Directory.Exists(targetFolderPath))
            return;

        srcFolderPath = Path.Combine(srcFolderPath, "nativelibs");

        DirectoryCopy(srcFolderPath, targetFolderPath, true);
    }

    private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
    {
        if (string.IsNullOrEmpty(sourceDirName) || string.IsNullOrEmpty(destDirName))
        {
            throw new ArgumentNullException(
                $"Directory paths cannot be empty. sourceDirName: {sourceDirName} | destDirName: {destDirName}");
        }

        var dir = new DirectoryInfo(sourceDirName);
        if (!dir.Exists)
        {
            throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " +
                                                 sourceDirName);
        }

        var dirs = dir.GetDirectories();
        if (!Directory.Exists(destDirName))
        {
            Directory.CreateDirectory(destDirName);
        }

        var files = dir.GetFiles();
        foreach (var file in files)
        {
            string temppath = Path.Combine(destDirName, file.Name);
            file.CopyTo(temppath, false);
        }

        if (copySubDirs)
        {
            foreach (var subdir in dirs)
            {
                var temppath = Path.Combine(destDirName, subdir.Name);
                DirectoryCopy(subdir.FullName, temppath, true);
            }
        }
    }
}
Asp.net在动态编译期间执行。它复制Grpc.Core.dll,但不复制包含本机Grpc_csharp_ext.dll文件的文件夹nativelibs。 我通过编程处理nativelibs文件夹解决了这个问题

从Global.asax中的应用程序_Start调用copy方法

public class WebApplication : HttpApplication
{
    protected void Application_Start()
    {
        GrpcInitializer.EnsureGrpcCSharpExtNativeDll();
    }
}
复印机:

public static class GrpcInitializer
{
    public static void EnsureGrpcCSharpExtNativeDll()
    {
        var grpcCoreAssembly = Assembly.GetAssembly(typeof(Grpc.Core.Channel));
        var srcFolderPath = Path.GetDirectoryName(new Uri(grpcCoreAssembly.CodeBase).LocalPath);

        CopyGrpcCSharpExtNativeDll(srcFolderPath);
    }

    public static void CopyGrpcCSharpExtNativeDll(string srcFolderPath)
    {
        var grpcCoreAssembly = Assembly.GetAssembly(typeof(Grpc.Core.Channel));
        var grpcDllLocation = Path.GetDirectoryName(grpcCoreAssembly.Location);
        if (grpcDllLocation == null)
            return;

        var targetFolderPath = Path.Combine(grpcDllLocation, "nativelibs");
        if (Directory.Exists(targetFolderPath))
            return;

        srcFolderPath = Path.Combine(srcFolderPath, "nativelibs");

        DirectoryCopy(srcFolderPath, targetFolderPath, true);
    }

    private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
    {
        if (string.IsNullOrEmpty(sourceDirName) || string.IsNullOrEmpty(destDirName))
        {
            throw new ArgumentNullException(
                $"Directory paths cannot be empty. sourceDirName: {sourceDirName} | destDirName: {destDirName}");
        }

        var dir = new DirectoryInfo(sourceDirName);
        if (!dir.Exists)
        {
            throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " +
                                                 sourceDirName);
        }

        var dirs = dir.GetDirectories();
        if (!Directory.Exists(destDirName))
        {
            Directory.CreateDirectory(destDirName);
        }

        var files = dir.GetFiles();
        foreach (var file in files)
        {
            string temppath = Path.Combine(destDirName, file.Name);
            file.CopyTo(temppath, false);
        }

        if (copySubDirs)
        {
            foreach (var subdir in dirs)
            {
                var temppath = Path.Combine(destDirName, subdir.Name);
                DirectoryCopy(subdir.FullName, temppath, true);
            }
        }
    }
}

Grpc社区已经在他们的Git存储库中修复了它。现在您只需要将grpc_csharp_ext.dll存储在该项目的bin\\nativelibs\\windows\u x86\\n下。他们在哪个版本中修复了它?我正在使用gRPC C#0.13.0。他们还没有发布新版本,它是0.14.0。我已经下载了Git存储库并在我的机器上重建了它。Grpc-Community已经在他们的Git存储库中修复了它。现在您只需要将grpc_csharp_ext.dll存储在该项目的bin\\nativelibs\\windows\u x86\\n下。他们在哪个版本中修复了它?我正在使用gRPC C#0.13.0。他们还没有发布新版本,它是0.14.0。我已经下载了Git存储库并在我的机器上重建了它。