首页 > 解决方案 > System.ArgumentException:通过 Hangfire 任务调用 NServiceBus 时路径不是合法形式

问题描述

当我尝试通过 Hangfire 任务调用 NServiceBus/Rabbit MQ 时出现以下错误我尝试将 .NET Framework 版本从 4.5.2 更新到 4.6.1

不知道我在这里做错了什么?我不断收到此错误但是,当我在本地(通过测试项目)运行它时,消息已成功放置在服务总线上(我能够在服务端点上看到它)

    System.AggregateException
One or more errors occurred.

System.AggregateException: One or more errors occurred. ---> System.ArgumentException: The path is not of a legal form.
   at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.Path.GetFullPath(String path)
   at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String fileName)
   at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
   at NServiceBus.Transport.RabbitMQ.ConnectionConfiguration.Create(String connectionString, String endpointName) in C:\BuildAgent\work\a9e6741f41af7061\src\NServiceBus.RabbitMQ\Configuration\ConnectionConfiguration.cs:line 141
   at NServiceBus.Transport.RabbitMQ.RabbitMQTransportInfrastructure..ctor(SettingsHolder settings, String connectionString) in C:\BuildAgent\work\a9e6741f41af7061\src\NServiceBus.RabbitMQ\RabbitMQTransportInfrastructure.cs:line 29
   at NServiceBus.RabbitMQTransport.Initialize(SettingsHolder settings, String connectionString) in C:\BuildAgent\work\a9e6741f41af7061\src\NServiceBus.RabbitMQ\RabbitMQTransport.cs:line 18
   at NServiceBus.InitializableEndpoint.<Initialize>d__1.MoveNext() in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\InitializableEndpoint.cs:line 49
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NServiceBus.Endpoint.<Start>d__1.MoveNext() in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\Endpoint.cs:line 27
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ERM.Messaging.ServiceBus.Client.ServiceBusClient.<StartAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at MeterServiceRequest.SyncMeterServiceRequest.<RunAsync>d__1.MoveNext()
   --- End of inner exception stack trace ---
   at MeterServiceRequest.SyncMeterServiceRequest.<RunAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at ERM.TaskRunner.Server.Impl.TaskWrapper.<RunAsync>d__0.MoveNext() in C:\Code\EMSCore\Apps\TaskRunner\TaskRunner.Server\Impl\TaskWrapper.cs:line 29
---> (Inner Exception #0) System.ArgumentException: The path is not of a legal form.
   at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.Path.GetFullPath(String path)
   at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String fileName)
   at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
   at NServiceBus.Transport.RabbitMQ.ConnectionConfiguration.Create(String connectionString, String endpointName) in C:\BuildAgent\work\a9e6741f41af7061\src\NServiceBus.RabbitMQ\Configuration\ConnectionConfiguration.cs:line 141
   at NServiceBus.Transport.RabbitMQ.RabbitMQTransportInfrastructure..ctor(SettingsHolder settings, String connectionString) in C:\BuildAgent\work\a9e6741f41af7061\src\NServiceBus.RabbitMQ\RabbitMQTransportInfrastructure.cs:line 29
   at NServiceBus.RabbitMQTransport.Initialize(SettingsHolder settings, String connectionString) in C:\BuildAgent\work\a9e6741f41af7061\src\NServiceBus.RabbitMQ\RabbitMQTransport.cs:line 18
   at NServiceBus.InitializableEndpoint.<Initialize>d__1.MoveNext() in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\InitializableEndpoint.cs:line 49
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NServiceBus.Endpoint.<Start>d__1.MoveNext() in C:\BuildAgent\work\b549d46003942065\src\NServiceBus.Core\Endpoint.cs:line 27
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ERM.Messaging.ServiceBus.Client.ServiceBusClient.<StartAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

标签: c#.netrabbitmqnservicebushangfire

解决方案


我们通过将 NService Bus 文件(包括 DLL)放在 Hangfire 任务所在的同一台服务器上解决了这个问题,并在 Hangfire 任务解决方案中添加了对 NService Bus 的引用


推荐阅读