Skip to content

Commit 6c942bf

Browse files
committed
fix a System.ArgumentNullException: 'Value cannot be null. (Parameter 'implementationType')'
here, since _opt.RouteInvocationInterceptor is null.
1 parent bc4cffd commit 6c942bf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Source/Extensions/ServiceCollectionExtensions.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static IServiceCollection AddMqttControllers(this IServiceCollection serv
5656

5757
services.AddSingleton<ITypeActivatorCache>(new TypeActivatorCache());
5858
services.AddSingleton<MqttRouter>();
59-
if (_opt.RouteInvocationInterceptor == null)
59+
if (_opt.RouteInvocationInterceptor != null)
6060
{
6161
services.AddSingleton(typeof( IRouteInvocationInterceptor), _opt.RouteInvocationInterceptor);
6262
}
@@ -101,15 +101,21 @@ public static IApplicationBuilder UseAttributeRouting(this IApplicationBuilder a
101101
var interceptor = app.ApplicationServices.GetService<IRouteInvocationInterceptor>();
102102
server.InterceptingPublishAsync += async (args) =>
103103
{
104-
await interceptor?.RouteExecuting(args.ClientId, args.ApplicationMessage);
104+
if (interceptor != null)
105+
{
106+
await interceptor.RouteExecuting(args.ClientId, args.ApplicationMessage);
107+
}
105108
try
106109
{
107110
await router.OnIncomingApplicationMessage(app.ApplicationServices, args, allowUnmatchedRoutes);
108111
}
109112
catch (Exception ex)
110113
{
111-
await interceptor?.RouteExecuted(args, ex);
112-
if (interceptor == null)
114+
if (interceptor != null)
115+
{
116+
await interceptor.RouteExecuted(args, ex);
117+
}
118+
else
113119
{
114120
throw;
115121
}

0 commit comments

Comments
 (0)