Hi team, please help to check this error
Telerik.Reporting.Serialization.SerializerExcepion HResult=0x80131500 Message=The XML serializer cannot resolve type with name: System.ComponentModel.ISite Source=Telerik.Reporting StackTrace: at Telerik.Reporting.Serialization.ObjectReader.ReadValue(Object obj, PropertyDescriptor prop) at Telerik.Reporting.Serialization.ObjectReader.ReadAttributes(Object obj, PropertyDescriptorCollection props) at Telerik.Reporting.Serialization.ObjectReader.ReadProperties(Object obj) at Telerik.Reporting.Serialization.ObjectReader.ReadObject(Type type) at Telerik.Reporting.Serialization.ObjectReader.ReadXmlElement(String name) at Telerik.Reporting.Serialization.ObjectReader.ReadCollection(Object collection) at Telerik.Reporting.Serialization.ObjectReader.ReadProperties(Object obj) at Telerik.Reporting.Serialization.ObjectReader.ReadObject(Type type) at Telerik.Reporting.Serialization.ObjectReader.ReadXmlElement(String name) at Telerik.Reporting.Serialization.ObjectReader.Deserialize(IResourceHandler handler) at Telerik.Reporting.JsonSerialization.JsonSerializer.Deserialize(String value) at Telerik.Reporting.JsonSerialization.JsonSerializer.Deserialize(StreamReader reader) at Telerik.Reporting.JsonSerialization.JsonSerializer.Deserialize(Stream stream) at Telerik.Reporting.JsonSerialization.ReportJsonSerializer.Deserialize(Stream stream) at MOS.ReportWriter.Web.Core.TelerikExtensions.ReportHelper.LoadReportFromDataWithDatasources(String reportData, List`1 webServiceDataSources) in C:\working\sourcecode\hrs-report\MOS.ReportWriter.Web\Core\TelerikExtensions\ReportHelper.cs:line 110 This exception was originally thrown at this call stack: [External Code] Inner Exception 1: InvalidCastException: Invalid cast from 'System.String' to 'System.ComponentModel.ISite'.
When i trying to modify the WebServiceDatasource in the report document with code below
public static Telerik.Reporting.Report LoadReportFromDataWithDatasources(string reportData, List<CustomeWebServiceDataSource> webServiceDataSources)
{
try
{
using MemoryStream stream = new(Convert.FromBase64String(reportData));
var reportPackager = new ReportPackager();
Telerik.Reporting.Report reportDocument = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(stream);
// Filter only WebServiceDataSources
var originalDataSources = reportDocument.GetDataSources();
var webServiceSources = originalDataSources.OfType<WebServiceDataSource>().ToList();
// Match and update existing WebServiceDataSources
var matchedDataSources = webServiceSources
.Where(ws => webServiceDataSources.Any(x => x.ServiceUrl == ws.ServiceUrl))
.ToList();
var unmatchedCustomSources = webServiceDataSources
.Where(x => !webServiceSources.Any(ws => ws.ServiceUrl == x.ServiceUrl))
.ToList();
var rebuiltDataSources = new List<object>();
foreach (var ws in matchedDataSources)
{
var matchingCustom = webServiceDataSources.FirstOrDefault(x => x.ServiceUrl == ws.ServiceUrl);
var paramValues = JsonConvert.DeserializeObject<Dictionary<string, object>>(matchingCustom?.ParameterValues);
var updatedWs = new CustomeWebServiceDataSource
{
Name = ws.Name,
DataEncoding = ws.DataEncoding.CodePage,
Method = ws.Method.ToString(),
Parameters = ws.Parameters.Select(p => new DataSourceParameter
{
Name = p.Name,
Value = new DataSourceParameterValue { Value = p.Value?.ToString() },
WebServiceParameterType = p.WebServiceParameterType.ToString()
}).ToList(),
ServiceUrl = ws.ServiceUrl,
DataSelector = ws.DataSelector
};
updatedWs.SetParameterValues(paramValues);
rebuiltDataSources.Add(updatedWs);
}
// Add new unmatched custom sources
rebuiltDataSources.AddRange(unmatchedCustomSources);
// Preserve non-WebServiceDataSources
var otherDataSources = originalDataSources.Where(ds => ds is not WebServiceDataSource);
rebuiltDataSources.AddRange(otherDataSources);
// Serialize updated report and inject data sources
var reportContent = SerializeReportToJson(reportDocument);
var reportJson = JsonConvert.DeserializeObject<JToken>(reportContent);
// Use full polymorphic list
reportJson["DataSources"] = JsonConvert.DeserializeObject<JArray>(JsonConvert.SerializeObject(rebuiltDataSources));
reportContent = JsonConvert.SerializeObject(reportJson);
using MemoryStream finalStream = new(System.Text.Encoding.UTF8.GetBytes(reportContent));
var serializer = new ReportJsonSerializer();
return (Telerik.Reporting.Report)serializer.Deserialize(finalStream);
}
catch
{
return null;
}
}
return (Telerik.Reporting.Report)serializer.Deserialize(finalStream);