升级Gremlin.net至3.6.2后出现Gremlin.net.dll找不到异常
Gremlin.Net 3.6.2升级后FileNotFoundException问题分析与解决
问题描述
将Gremlin.Net从3.6.1升级到3.6.2后,在Startup.cs实例化GremlinClient时抛出FileNotFoundException,提示在项目根目录找不到Gremlin.Net.dll,而非预期的bin输出目录。手动复制该DLL到根目录可临时解决,但不符合常规部署逻辑。
相关代码片段:
services.AddSingleton<GremlinClient>(s => { GremlinServer server = new GremlinServer(hostname: "host", port: 443, enableSsl: true, username: $"collection", password: "password"); var connectionPoolSettings = new ConnectionPoolSettings { MaxInProcessPerConnection = 32, PoolSize = 4, ReconnectionAttempts = 4, ReconnectionBaseDelay = TimeSpan.FromSeconds(1) }; var socket = new Action<ClientWebSocketOptions>(o => { o.KeepAliveInterval = TimeSpan.FromSeconds(10); }); return new GremlinClient(server, new GraphSON2MessageSerializer(), connectionPoolSettings, socket); });
异常栈关键链路:
at System.Reflection.Metadata.MetadataReader.GetAssemblyName(String assemblyFile) at Gremlin.Net.Process.Utils.GenerateUserAgent() at Gremlin.Net.Process.Utils.get_UserAgent()
原因分析
3.6.2版本的Gremlin.Net在GenerateUserAgent()方法中,直接使用相对路径"Gremlin.Net.dll"调用MetadataReader.GetAssemblyName()获取版本信息,用于生成UserAgent字符串。而程序运行时的当前工作目录默认是项目根目录(而非bin输出目录),导致系统尝试在根目录查找该DLL,引发文件未找到异常。
这是Gremlin.Net 3.6.2版本引入的bug,后续版本已修复该路径问题。
解决方案
- 升级到修复版本:将Gremlin.Net升级至3.6.3或更高版本,官方已修正该路径查找逻辑,改为从程序集加载上下文获取版本信息,不再依赖物理文件路径。
- 调整运行工作目录:在项目属性的“调试”选项中,将“工作目录”设置为输出目录(如
$(TargetDir)),确保运行时当前目录指向bin文件夹。 - 临时 workaround:若暂时无法升级,可将
Gremlin.Net.dll复制到项目根目录,但此方法仅适用于开发环境,不建议生产部署使用。
内容的提问来源于stack exchange,提问作者Andreas Herigstad
相关产品推荐
相关产品推荐

