更新后 ImageResizer 抛出 "Object reference not set to an instance of an object."

ImageResizer throws "Object reference not set to an instance of an object." after update

我正在尝试使用 NuGet 的最新 ImageResizer 包更新我们的解决方案。

更新后,我得到了以下空异常。所以我尝试恢复我的解决方案并再次更新包。同样的问题。 我也尝试使用 ImageResizer 中内置的诊断页面,但这也有同样的问题。 在 NuGet 更新期间没有出现问题。

堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.]
   ImageResizer.Configuration.PluginConfig.ParseName(String typeName) +8
   ImageResizer.Configuration.PluginConfig.FindPluginType(String searchNameString) +99
   ImageResizer.Configuration.PluginConfig.add_plugin_by_name(String name, NameValueCollection args) +16
   ImageResizer.Configuration.PluginConfig.loadPluginsInternal() +214
   ImageResizer.Configuration.PluginConfig.LoadPlugins() +93
   ImageResizer.Configuration.Config..ctor(ResizerSection config) +393
   ImageResizer.Configuration.Config.get_Current() +109
   ImageResizer.InterceptModule.System.Web.IHttpModule.Init(HttpApplication context) +276
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +536
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

web.config 中的缩放器设置:

  <resizer>
    <plugins>  
      <add name="AzureReader2" prefix="~/cloud/" connectionString="DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXX" endpoint="https://XXX.windows.net/" />
      <add logging="true" />
      <add name="DiskCache" />
    </plugins>
    <clientcache minutes="60" />
    <diskcache enabled="true" dir="~/App_Data/DiskCache" AutoClean="true" hashModifiedDate="true" subfolders="32" cacheAccessTimeout="15000" asyncWrites="false" asyncBufferSize="10485760" />
    <cleanupStrategy startupDelay="00:05" minDelay="00:00:20" maxDelay="00:05" optimalWorkSegmentLength="00:00:04" targetItemsPerFolder="400" maximumItemsPerFolder="1000" avoidRemovalIfCreatedWithin="24:00" avoidRemovalIfUsedWithin="4.00:00" prohibitRemovalIfUsedWithin="00:05" prohibitRemovalIfCreatedWithin="00:10" />
  </resizer>

您可以在错误消息中看到错误发生在 PluginConfig.ParseName(String typeName) - 因为这是空引用错误,这强烈暗示名称为空。

查看配置的插件部分,很明显您没有为 logging 插件指定名称:

<add logging="true" />

documentation 表示这是正确的语法:

<add name="Logging" />