My plugin class implements a service. I inject Nop.Services.Logging.ILogger into this service class in my plugin and it works OK when an instance of the class is "called normally" via injection when used as a service. But now I've added an ActionFilter (in the same plugin) that calls a method in the service class. When it reaches the _logger.Information() in the service class, an exception is thrown. It seems as if the httpContext is missing something during the ActionFilter processing:
[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.VisualStudio.WebHost.Connection.get_RemoteIP() +0
Microsoft.VisualStudio.WebHost.Request.GetRemoteAddress() +65
System.Web.HttpRequestWrapper.get_UserHostAddress() +22
Nop.Core.WebHelper.GetCurrentIpAddress() in \Libraries\Nop.Core\WebHelper.cs:53
Nop.Services.Logging.DefaultLogger.InsertLog(LogLevel logLevel, String shortMessage, String fullMessage, Customer customer) in \Libraries\Nop.Services\Logging\DefaultLogger.cs:183
Nop.Services.Logging.LoggingExtensions.FilteredLog(ILogger logger, LogLevel level, String message, Exception exception, Customer customer) in \Libraries\Nop.Services\Logging\LoggingExtensions.cs:39
Nop.Services.Logging.LoggingExtensions.Information(ILogger logger, String message, Exception exception, Customer customer) in \Libraries\Nop.Services\Logging\LoggingExtensions.cs:15
[My Plugin method]
CallSite.Target(Closure , CallSite , [My Plugin class] , Object ) +259
[My Namespace].ActionFilters.ActionFilterPreparePaymentInfoModel.OnActionExecuted(ActionExecutedContext filterContext) +630
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +283
...
\Libraries\Nop.Core\WebHelper.cs
public virtual string GetCurrentIpAddress()
{
if (_httpContext != null &&
_httpContext.Request != null &&
_httpContext.Request.UserHostAddress != null)
return _httpContext.Request.UserHostAddress; <<<<Exception Thrown here
return string.Empty;
}
Any thoughts / workarounds?