【发布时间】:2017-11-21 11:41:36
【问题描述】:
我有一个对象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);
函数A
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
....
}
【问题讨论】:
-
"即使对象不是空的"哪个对象?
parameters在functionA内?到目前为止,我无法重现您的问题 -
也许是个愚蠢的问题,但为什么不将functionA的类型改为
public static byte[] functionA(RS2005.ParameterValue[] parameters),并获得编译时类型安全的帮助呢?通过object再返回似乎是不必要的风险。 -
@StuartLC 或者使用直接演员而不是演员。
标签: c# reporting-services casting parameter-passing