3

我正在使用 Project Hawaii SDK 来创建 Speech to Text 应用程序。我运行了示例项目,并在启动时引发了以下异常。

System.Reflection.TargetInvocationException was unhandled by user code
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
InnerException: System.MethodAccessException
   HResult=-2146233072
   Message=Attempt by security transparent method 'System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)' to access security critical method 'System.IO.File.Exists(System.String)' failed.
   Source=mscorlib
   InnerException: 

我看到了异常描述,但是我找不到合适的解决方案。这是发生错误的块代码。

 try
        {
            bool fileExists = (bool)existsMethodInfo.Invoke(null, new object[] { configFilePath });

            if (fileExists)
            {
                IEnumerable<string> lines = (IEnumerable<string>)readLinesMethodInfo.Invoke(null, new object[] { configFilePath });
                foreach (string line in lines)
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        return line;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }

进行这些调用的函数的摘要是“该函数用于查找指定文件中的设置。如果不存在,则返回默认值。由于 CA2140 分析规则,需要 [SecurityCritical] 属性。

4

0 回答 0