我有一个对象RS2005.ParameterValue[] parameters
。我声明它的标签,名称和值。然后我将它传递给另一个函数,让我们称之为A.
当我尝试将它分配给函数A中RS2005.ParameterValue []类型的临时变量temp
时,它返回null,即使该对象不为空(根据调试器)。这个功能在几个版本之前运行良好,但最近它停止了工作,我想知道它是否可能与Visual Studio版本更改到2015年有什么关系?
原始功能
RS2005.ParameterValue[] parameters = new RS2005.ParameterValue[5];
parameters[0] = new RS2005.ParameterValue();
parameters[0].Label = "a";
parameters[0].Name = "a";
parameters[0].Value = "AA";
.....
frontPageBytes = Functions.functionA(parameters);
泛函
public static byte[] functionA(object parameters)
{
byte[] bytes = null;
RS2005.ReportExecutionService rsExec = new RS2005.ReportExecutionService();
rsExec.Credentials = new NetworkCredential(RSServerUserLogin, RSServerUserPassword, RSServerUserDomain);
rsExec.Url = RSServerWSURI;
string deviceInfo = string.Format(@"<DeviceInfo><OutputFormat>{0}</OutputFormat></DeviceInfo>", "PDF");
RS2005.ExecutionInfo ei = rsExec.LoadReport(rdlPath, null);
RS2005.ParameterValue[] temp = parameters as RS2005.ParameterValue[]; <---------- This temp is null
rsExec.SetExecutionParameters(parameters as RS2005.ParameterValue[], "en-us"); <---------- this throws an exception because parameters is null
....
}
答案 0 :(得分:0)
我找到了答案。我在问题中没有提到的是功能A,原始功能在不同的项目中。这与我必须转换为object
然后回到RS20005.ParameterValue []的原因有关。
我没有注意到,项目A和项目B的报告查看器版本略有不同。当我使用as
进行投射时,C#试图通过返回null来保存我,这使我无法找到错误。只有在直接投射后才能找到问题的原因。