简体   繁体   中英

C# Telerik Load Assembly Error (StartIndex cannot be less than zero.)

I have some Telerik reports that are stored in database. To convert them into Reports I used such piece of code:

private Telerik.Reporting.Report GetReportFromXml(string xmlString)
{
    using (StringReader xmlReader = new StringReader(xmlString))
    {
        Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
        object res = xmlSerializer.Deserialize(xmlReader);
        return res as Telerik.Reporting.Report;
    }
}

Also I have two databases with absolutely same xmlString data.

The Problem:

With first database all works fine.

With second I get error on xmlSerializer.Deserialize(xmlReader) :

CurrentDomain_UnhandledException
System.IO.FileLoadException: Could not load file or assembly 'Telerik.Reporting.Design, Version=10.1.16.504, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' or one of its dependencies. An argument was out of its legal range. (Exception from HRESULT: 0x80131502)
File name: 'Telerik.Reporting.Design, Version=10.1.16.504, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' ---> System.ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Parameter name: startIndex
   at System.String.Substring(Int32 startIndex, Int32 length)
   at ?A0x6aa5279c.domain_AssemblyResolve(Object __unnamed000, ResolveEventArgs args)
   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName)
   at System.ComponentModel.PropertyDescriptor.GetTypeFromName(String typeName)
   at System.ComponentModel.PropertyDescriptor.get_Converter()
   at Telerik.Reporting.Xml.ObjectXmlReaderWriterBase.GetTypeConverter(PropertyDescriptor prop)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadValue(Object obj, PropertyDescriptor prop)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadAttributes(Object obj, PropertyDescriptorCollection props)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadProperties(Object obj)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadObject(Type type)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadXmlElement(String name)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadCollection(Object collection)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadProperties(Object obj)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadObject(Type type)
   at Telerik.Reporting.Xml.ObjectXmlReader.ReadXmlElement(String name)
   at Telerik.Reporting.Xml.ObjectXmlReader.Deserialize(IResourceHandler handler)
   at Telerik.Reporting.Xml.XmlSerializer.Deserialize(TextReader reader, IResourceHandler resourceHandler)
   at Telerik.Reporting.XmlSerialization.ReportXmlSerializer.Deserialize(TextReader reader)

I want to mention that I use the same source code and I'm totally sure that parameter xmlString is equal in both situation. I just changing connection and error appears.

I presume it's some database setting that force assembly to load. But project is huge and don't have a clue as to how to fix this and what I should pay attention to.

Telerik Reporting assemblies are strong-name signed and the error that you are reporting looks like a version incompatibility between current assemblies. In order to rule this out, update all your references (if using NuGet install/uninstall) and ensure that all of the Telerik Reporting dependencies have the same version. I assume that the different behavior between the two data connections is a side effect, rather than the original reason behind the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM