C# 运行Project夏威夷示例应用程序时System.Reflection.TargetInvocationException异常
我正在使用夏威夷SDK项目创建语音到文本应用程序。我运行了示例项目,在启动时引发了以下异常C# 运行Project夏威夷示例应用程序时System.Reflection.TargetInvocationException异常,c#,windows-phone-7,reflection,C#,Windows Phone 7,Reflection,我正在使用夏威夷SDK项目创建语音到文本应用程序。我运行了示例项目,在启动时引发了以下异常 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.MethodAc
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;
}
}
}
}
试试看
{
bool fileExists=(bool)existsMethodInfo.Invoke(null,新对象[]{configFilePath});
如果(文件存在)
{
IEnumerable lines=(IEnumerable)readLinesMethodInfo.Invoke(null,新对象[]{configFilePath});
foreach(行中的字符串行)
{
如果(!string.IsNullOrEmpty(行))
{
回流线;
}
其他的
{
打破
}
}
}
}
进行这些调用的函数的摘要是“函数在指定文件中查找设置时使用。如果不存在,则返回默认值。由于CA2140分析规则,需要[SecurityCritical]属性