You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Set-WebConfigurationProperty偶发NullReferenceException异常求助

偶发NullReferenceException:调用Set-WebConfigurationProperty设置IIS Windows身份验证时

在配置IIS网站属性过程中,偶发性出现NullReferenceException,且无法稳定重现,导致无法测试解决方案或规避思路。

出错代码

执行以下PowerShell命令时触发异常:

Set-WebConfigurationProperty -filter "/system.webServer/security/authentication/$($Type)Authentication" -name Enabled -value $valueText -PSPath "IIS:\" -Location $ApplicationName

其中变量值:

  • $Type = "Windows"
  • $valueText = "False"

异常信息

报错包含德语内容(对应英文NullReferenceException,德语原文意为“未将对象引用设置到对象的实例”):

Set-WebConfigurationProperty : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
In C:\[REDACTED]\Modules\IIS-Application-Configuration.psm1:83 Zeichen:5
+     Set-WebConfigurationProperty -filter "/system.webServer/security/ ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Set-WebConfigurationProperty], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand

已尝试操作

  • 重新运行代码后异常自行消失
  • 在另一环境中先停用目标IIS站点再执行命令,但因无法重现问题,无法确认是否有效(脚本逻辑中本就要求执行该行前停用站点)
  • 常规网络搜索未找到有效解决方案

求助

  • 是否有开发者遇到过相同的偶发异常?
  • 能否解释该现象的潜在原因?
  • 提供稳定的复现方法,以便针对性处理并验证修复方案

内容的提问来源于stack exchange,提问作者Chris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 23:45:11