调用RSDK组件SpeechDocument构造函数时遇Path2空值异常求助
第三方RSDK SpeechDocument构造函数抛出System.ArgumentNullException(Path.Combine的path2参数)
问题场景
已成功引用第三方RSDK程序集,使用RSDK.Reporting.SpeechDocument构造函数时触发System.ArgumentNullException,错误提示Path.Combine的path2参数为空,但代码中未直接调用该方法,WAV文件路径位于项目外部。
相关代码
public string Post() { // SpeechDocument(String waveFilePath, String authorName, String reportingGroup, Boolean isTelephonyFile) SpeechDocument doc = new SpeechDocument(@"C:\...\00000001.wav", "Cedrick", "General Medicine", false); return "success"; }
注:原代码中的路径写法
"C:\...\00000001.wav"存在转义问题,需改为@前缀或双反斜杠\\避免解析错误。
报错信息
at System.IO.Path.Combine(String path1, String path2) at RSDK.Internal.Common.RSDKContainer.get_CurrentProcessLogFileNameWithPath() at RSDK.Internal.Core.SpeechDocumentCore.#=z$5Q2T_xRYoga() at RSDK.Internal.Core.SpeechDocumentCore.EndEditing(Boolean #=zTYSHoeyj3r48ojXOIRdOcpA=, AudioRecorderEvent[] #=zbELmHJ$IRdFI, RecognitionSessionEvents #=zBhjJtc_kJDyoD0OJyFahi54=) at RSDK.Reporting.SpeechDocument.#=zP0d4cWexHDDrvOhI7Q==(Byte[] #=zF8R1D8iiYw7u, String #=znyXcsaU=, String #=z7F6fUgeQvXwBuhoM2Q==, Boolean #=zX9EJOBrNDRht3FrkZg==) at RSDK.Reporting.SpeechDocument..ctor(String waveFilePath, String authorName, String reportingGroup, Boolean isTelephonyFile) at RSDKAPII.Controllers.ValuesController.Post() in C:\Users\Cedric\Desktop\TestProject\RSDKAPII\Controllers\ValuesController.cs:line 51 at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
解决方案
从调用栈分析,错误并非来自传入的WAV路径,而是RSDK内部在生成日志文件路径时触发的:RSDKContainer.get_CurrentProcessLogFileNameWithPath()方法调用Path.Combine时,第二个参数为空,说明SDK的日志路径配置缺失或无效。
可按以下步骤排查解决:
- 检查SDK配置文件:查看app.config/web.config中是否存在RSDK相关的日志路径配置项(如
RSDKLogDirectory),确保其值为有效的、可写入的文件夹路径。 - 手动设置日志路径:如果SDK提供公开API,在初始化
SpeechDocument前手动指定日志目录,例如:// 假设SDK提供该方法,需根据实际API调整 RSDK.Internal.Common.RSDKContainer.SetLogPath(@"C:\RSDK_Logs"); - 验证应用工作目录:通过
Directory.GetCurrentDirectory()检查当前应用的工作目录是否正常,若工作目录为空或无权限,可能导致SDK内部路径拼接失败,需确保工作目录有效。 - 修正路径写法:确保WAV文件路径使用正确的转义格式(
@前缀或双反斜杠),避免路径解析异常。
内容的提问来源于stack exchange,提问作者Newbie
相关产品推荐
相关产品推荐

