Project WPF .Net 3.5 in visual studio 2010 cause error - c#

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.

Related

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.

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 :)

Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))

I have installed VS2008 (SP1) on Windows 7 (64bit) machine.
When I run the VS IDE in "Run as administrator" mode and create a new Winform application or open the design view of a Form in an already existing application, I get following error message:
Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))
The stack trace for this error is given below:
at EnvDTE.Project.get_Properties()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.get_References()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.EnsurePopulated(Boolean fPopulateProject)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchNormalEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, Boolean fastSearch)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchEntries(AssemblyName assemblyName, String typeName, Boolean ignoreCase, Assembly& assembly, ReferenceType refType)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.GetType(String typeName)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
However, everything works fine if I am running the IDE in normal mode (i.e not "Run as administrator")
I have seen previous questions related to this error message but most of them are irrelevant.

Categories

Resources