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

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.

Related

Cannot get Type declared in a .NET Framework assembly from a .NET Core 2 assembly

I have a .NET Core 2 console app which is performing some maintenance/upgrade work on the DB underlying a ASP.NET website running on .NET Framework 4.7.1.
The console app needs to read in the assembly-qualified type names of classes which are declared in the .NET Framework assemblies. It does this using Type.GetType("[assembly-qualified name]";
This code works perfectly well for the built-in .NET types but it throws an exception when it comes to types defined in our own assemblies. Confusingly, I can declare a variable of one of these types in the .NET Core console app but I'm unable to instantiate a Type object referencing the same type.
For example, this works...
var cs = Common.CustomerManagement.Person.CustomerStatus.ApprovedCustomer;
but this...
var ct = Type.GetType("Common.CustomerManagement.Person+CustomerStatus, Common, Version=1.0.6793.16016, Culture=neutral, PublicKeyToken=null;");
...throws the exception...
System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
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)
I realise that in the code which works I'm referencing an enum on the type and in the code which doesn't work I'm referencing just the type, but the working code shows that the referenced .NET Framework assembly can be loaded whereas the non-working code suggests that the type is not available to the .NET Core console app.
The problem was that the type name is the Type.AssemblyQualifiedName which includes a version number.
It's the version number which was causing the problem. Once I removed the version number and left the other information in the type name, it worked.

3rd party assembly is looking for a specific version of log4net- how do I resolve this?

I am trialing a cloud based logging system whereby I have to setup an appender for log4net in my App.config file.
It is working fine when I run it on my development PC, however when I run it on my server, I get this:
log4net:ERROR Could not create Appender [LeAppender] of type [log4net.Appender.LogentriesAppender, LogentriesLog4net]. Reported error follows.
System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
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, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
I have log4net 2.0.8.0 however it looks like this assembly is specifically referencing version 1.2.13.0 (confirmed with dotPeek).
I've never using binding redirects but I'm fairly certain this would help in this case. However, why does it work on my local machine? Is this because my local machine has a copy of that version somewhere (such as in the GAC or somewhere else?).
Also.. the documentation for logentries has nothing related to having to use a specific version of log4net.. surely they would have had this issue crop up before?

Parse.dll 1.6.0 does not have a strong name

It appears Parse.dll and Parse.NetFx45.dll from the .net 4.5 package do not have a strong name.
I have also tried signing them with my .snk, but I still have this exception when launching my app:
Could not load file or assembly 'Parse, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
StackTrace: 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 Parse.ParseClient.GetParseType(String name)
at Parse.ParseClient..cctor()
I have followed this guide to sign it personally: http://ryanfarley.com/blog/archive/2010/04/23/sign-a-.net-assembly-with-a-strong-name-without-recompiling.aspx
But it does not work.
When showing properties of the said dlls in visual studio, it does say they have a strong name.
Any idea?
To people coming across this problem, the issue was reported to the Parse developers and they have fixed it.
Happy codding folks :)

It is recommended to provide a fully specified textual identity for the assembly

I want to instantiate a class at runtime using
_syncHelper = (ISyncHelper) Activator.CreateInstance("SBD.Syrius.Synchronisation", "SyncHelper");
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
System.IO.FileNotFoundException: Could not load file or assembly
'SBD.Syrius.Synchronisation' or one of its dependencies. The system cannot find the file specified.
File name: 'SBD.Syrius.Synchronisation'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at SBD.Syrius.DataLayer.DataHelper.get_SyncHelper() in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\DataHelper.cs:line 35
at SBD.Syrius.DataLayer.Context.SaveChanges() in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\Context.cs:line 99
at SBD.Syrius.UI.MDIHelper.AttemptToSave(Context Db) in e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\MDIHelper.cs:line 51
=== Pre-bind state information ===
LOG: User = saturn\kirsten
LOG: DisplayName = SBD.Syrius.Synchronisation
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: SBD.Syrius.Synchronisation | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information
and common solutions to this issue.
LOG: Appbase = file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : SBD.Syrius.DataLayer, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file:
E:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\bin\Debug\SBD.Syrius.UI.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or
location-based assembly bind).
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation.DLL.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation/SBD.Syrius.Synchronisation.DLL.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation.EXE.
LOG: Attempting download of new URL file:///E:/EShared/Syrius6/syrius_syrius/SBD.Syrius.UI/bin/Debug/SBD.Syrius.Synchronisation/ SBD.Syrius.Synchronisation.EXE.
The error I receive contains a link to MSDN here, but I cannot find an example of how to specify textual identity for the assembly.
I note that the full error indicates that it is looking int the wrong folder and also for a file with an uppercase .DLL . My file is creating with a lowercase .dll
Is there an example of how to provide a fully specified textual identity for an assembly?
Should I be trying to change the case of the .dll extension?
If I actually copy the .dll to the UI\bin\debug folder then I get a different error
A first chance exception of type 'System.TypeLoadException' occurred in mscorlib.dll
System.TypeLoadException: Could not load type 'SyncHelper'
from assembly
'SBD.Syrius.Synchronisation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name,
Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at SBD.Syrius.DataLayer.DataHelper.get_SyncHelper() in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\DataHelper.cs:line 35
at SBD.Syrius.DataLayer.Context.SaveChanges() in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.DataLayer\Context.cs:line 99
at SBD.Syrius.UI.MDIHelper.AttemptToSave(Context Db) in
e:\EShared\Syrius6\syrius_syrius\SBD.Syrius.UI\MDIHelper.cs:line 51
Spot three errors:
Activator.CreateInstance needs the complete name of type to load it
it means that you must add namespace to the type name.
Chances are you have more than one class with that name in different namespaces then how it could figure out which one be loaded.
You want to create an instance of an Interface which is impossible.
ISyncHelper is an interface and you can not say:
var variable = new ISynchHelper()
It will cause compilation error, cause interfaces are just empty bodies and does not contain single line of implementation.
So evertime that you use reflection to do smething, be careful, cause the compiler can not help you and if something is supposed to go wrong, you'll face it in runtime, not in compile time.
Last error is due to that there is no reference to Synchronization project in UI which means that it will not copied to Bin folder of UI project.
You can do that by adding the Synchronization project to UI or just add a copy command to Synchronization project to be copied after build.
Good Luck :-)

Project WPF .Net 3.5 in visual studio 2010 cause error

I have the problem when I create blank wpf .Net 3.5 project. Visual studio has throw an error and stop working. This is very strange because when I created other project in .Net 3.5 like windows form, it worked (aslo I have tested in other .Net framework without error).
Here is the copied error detail:
System.ArgumentException
Type universe cannot resolve assembly: System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
at System.Reflection.Adds.TypeNameParser.DetermineAssembly(AssemblyName assemblyName, Module defaultTokenResolver, ITypeUniverse universe)
at System.Reflection.Adds.TypeNameParser.<>c__DisplayClass2.<ParseTypeName>b__0(AssemblyName assemblyName)
at System.TypeNameParser.ResolveAssembly(String asmName, Func`2 assemblyResolver, Boolean throwOnError, StackCrawlMark& stackMark)
at System.TypeNameParser.ConstructType(Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError)
at System.Reflection.Adds.TypeNameParser.ParseTypeName(ITypeUniverse universe, Module module, String input, Boolean throwOnError)
at Microsoft.MetadataReader.UnresolvedTypeName.ConvertToType(ITypeUniverse universe, Module moduleContext)
at Microsoft.MetadataReader.MetadataExtensionsPolicy20.TryTypeForwardResolution(MetadataOnlyAssembly assembly, String fullname, Boolean ignoreCase)
at Microsoft.MetadataReader.MetadataOnlyAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.MetadataReader.MetadataOnlyAssembly.GetType(String name)
at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.GetAssemblyType(Reflectable`1 assembly, String typeName)
at MS.Internal.Metadata.ClrAssembly.GetType(String typeName)
at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.LoadType(String typeName)
at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.GetType(String fullName)
at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.GetType(String fullName)
at Microsoft.Windows.Design.Metadata.IdentifierExtensionImplementations.GetType(IMetadataContext scope, TypeIdentifier typeId)
at MS.Internal.Design.Metadata.Xaml.XamlAssembly.get_XmlNamespaceCompatibilityMappings()
at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.GetXmlNamespaceCompatibilityMappings(IAssemblyMetadata sourceAssembly)
at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensions.GetXmlNamespaceCompatibilityMappings(IAssemblyMetadata source)
at MS.Internal.Design.Metadata.ReflectionProjectNode.BuildSubsumption()
at MS.Internal.Design.Metadata.ReflectionProjectNode.SubsumingNamespace(Identifier identifier)
at MS.Internal.Design.Markup.XmlElement.BuildScope(PrefixScope parentScope, IParseContext context)
at MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent, PrefixScope parentScope, IParseContext context, IMarkupSourceProvider provider)
at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.FullParse(Boolean convertToXamlWithErrors)
at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.get_RootItem()
at Microsoft.Windows.Design.DocumentModel.Trees.ModifiableDocumentTree.get_ModifiableRootItem()
at Microsoft.Windows.Design.DocumentModel.MarkupDocumentManagerBase.get_LoadState()
at MS.Internal.Host.PersistenceSubsystem.Load()
at MS.Internal.Host.Designer.Load()
at MS.Internal.Designer.VSDesigner.Load()
at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.Load()
at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedDesignerFactory.Load(IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.Load()
at MS.Internal.Designer.DesignerPane.LoadDesignerView()
Image:
Also I tried repairing, uninstalling and reinstalling Visual Studio but it still has error. Any help?
Update: error is only occurring when I open xaml file.
For some reason there is a reference to system.XAML 4.0 in your 3.5 code. Unload your project, and then edit it. Find the line that has the system.XAML in it, and get rid of it. You can add the 3.5 version in manually after you reload your project.
Finnaly, I have fixed it. When I tried to update VS SP1, I received the error
The installation log file could not be written. Verify that the Temp
folder exists and that you can write to it.
Then I recognize the %temp% directory doesn't access. Then I go to environment variables and change %temp% path (I never touch this variable before), and the setup VS SP1 worked well. Also, this WPF error is fixed.

Categories

Resources