Exception when calling StiReport.GetReportFromAssembly(assembly)
Posted: Thu Aug 11, 2011 4:20 am
When calling StiReport.GetReportFromAssembly(assembly) located in "Stimulsoft.Report.SL.dll", an InvalidCastException is raised with the following error message:
"Unable to cast object of type 'System.Object[]' to type 'Stimulsoft.Report.StiReport[]'."
I took a look at the code, and it seems that the problem is because of an invalid cast from ArrayList to StiReport[]:
public static StiReport[] GetReportsFromAssembly(Assembly assembly)
{
try
{
ArrayList list = new ArrayList();
foreach (Type type in assembly.GetTypes())
{
if (type.IsSubclassOf(typeof(StiReport)))
{
StiReport item = StiActivator.CreateObject(type) as StiReport;
item.ApplyStyles();
list.Add(item);
}
}
return (StiReport[]) list.ToArray();
}
catch
{
if (!HideExceptions)
{
throw;
}
}
return null;
}
It seems this problem only exists in silverlight version, because in the "Stimulsoft.Report.dll" assembly the cast seems to be applied correctlly:
return (StiReport[]) list.ToArray(typeof(StiReport));
Thank you in advance.
"Unable to cast object of type 'System.Object[]' to type 'Stimulsoft.Report.StiReport[]'."
I took a look at the code, and it seems that the problem is because of an invalid cast from ArrayList to StiReport[]:
public static StiReport[] GetReportsFromAssembly(Assembly assembly)
{
try
{
ArrayList list = new ArrayList();
foreach (Type type in assembly.GetTypes())
{
if (type.IsSubclassOf(typeof(StiReport)))
{
StiReport item = StiActivator.CreateObject(type) as StiReport;
item.ApplyStyles();
list.Add(item);
}
}
return (StiReport[]) list.ToArray();
}
catch
{
if (!HideExceptions)
{
throw;
}
}
return null;
}
It seems this problem only exists in silverlight version, because in the "Stimulsoft.Report.dll" assembly the cast seems to be applied correctlly:
return (StiReport[]) list.ToArray(typeof(StiReport));
Thank you in advance.