【问题标题】:Getting unhandled Exception: System.ArgumentNullException获得未处理的异常:System.ArgumentNullException
【发布时间】:2021-01-03 02:24:19
【问题描述】:

我在运行控制台应用程序时遇到以下异常: 我在远程机器上运行的 Jenkins 服务器上面临构建问题(在发布模式下)。 我正在处理命令行参数,我认为错误原因意味着运行 exe 时没有传递任何参数。

    unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: path
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at VstoManifestGenerator.Program.WriteOutput(String entry, Object[] args) in C:\Dev\Client\VstoManifestGenerator\VstoManifestGenerator\Program.cs:line 318
   at VstoManifestGenerator.Program.Main(String[] args) in C:\Dev\Client\VstoManifestGenerator\VstoManifestGenerator\Program.cs:line 164

下面是我的命令行参数:

C:\Dev\Client\AddIns\Office\Word2010AddIn\bin\XTS.Office.AddIn.Word.dll Debug amd64

我在调试配置的本地开发机器上没有这个问题,我没有弄清楚是什么导致了这个问题。

这里谁能帮我解决一下。

谢谢。

【问题讨论】:

  • 这是您应该了解minimal reproducible example的时候了
  • 您将_ouputfile 第一次(潜在)调用后设置为WriteOutput。 (主要)
  • ^^ 您在catch(Main 中的外部)中调用WriteOutput,其中_ouputfile 可能尚未设置。我猜这是 Stacktrace 的第 164 行?
  • 如果您告诉我们发生异常的行会有所帮助。使用 F11 单步执行代码并使用 F9 设置断点。

标签: c# .net xml visual-studio jenkins


【解决方案1】:

调用WriteOutput 时,堆栈跟踪提示_outputfile 尚未设置。

确保在WriteOutput 进行任何调用之前对其进行初始化。

心灵:

string dependency;

try{

    // exception thrown HERE

    dependency = "somepath"; // <= Will not be executed
}
catch
{
    CallToMethodDependingOnDependency() // <= Will throw again
}

乍一看,这个看起来就像是在设置了依赖关系之后调用,但是异常跳转了初始化。

【讨论】:

  • 我按照你说的做了。我发现当 "Mage(string.Format(@"-Update ""{0}"" -Version {1} -FromDirectory ""{2}"" ", tempManifest, 版本, finfo.Directory.FullName));"被调用。
  • 结果字符串变量包含以下字符串值“内部错误,请重试。此程序集由比当前加载的运行时更新的运行时构建,无法加载。(来自 HRESULT 的异常:0x8013101B) . 并且这个字符串值作为 WriteOutput() 方法的参数传递
  • 另外,当我在发布配置中运行相同的应用程序时,它会抛出异常“System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'”
  • 是什么导致了这个问题?
  • 这些是不同的问题。您提到的第一个似乎是安装在目标计算机上的 dotnet 框架的旧版本,而不是您的应用程序目标版本。后者……不知道。但这也是另一个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-19
相关资源
最近更新 更多