Recently in my project we migrated from VS2003 to VS2005. The application I am working on is a smart client application so it has lot many Win Forms. After migration, when the solution was opened up in VS2005, we faced this strange problem. None of the Forms were opening in the designer mode. It was throwing exception (shown below)
|
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes. |
|
Object reference not set to an instance of an object. Hide
|
|
at System.Resources.Tools.StronglyTypedResourceBuilder.DefineResourceFetchingProperty(String propertyName, String resourceName, ResourceData data, CodeTypeDeclaration srClass, Boolean internalClass, Boolean useStatic) at System.Resources.Tools.StronglyTypedResourceBuilder.InternalCreate(Dictionary`2 resourceList, String baseName, String generatedCodeNamespace, String resourcesNamespace, CodeDomProvider codeProvider, Boolean internalClass, String[]& unmatchable) at System.Resources.Tools.StronglyTypedResourceBuilder.Create(IDictionary resourceList, String baseName, String generatedCodeNamespace, String resourcesNamespace, CodeDomProvider codeProvider, Boolean internalClass, String[]& unmatchable) at System.Resources.Tools.StronglyTypedResourceBuilder.Create(IDictionary resourceList, String baseName, String generatedCodeNamespace, CodeDomProvider codeProvider, Boolean internalClass, String[]& unmatchable) at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObject.BuildType() at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObject.GetObjectType() at Microsoft.VisualStudio.Shell.Design.GlobalType.get_ObjectType() at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObject.get_Children() at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObjectProvider.CreateGlobalObjectsForItem(ProjectItem item, GlobalObjectCollection oldObjects, GlobalObjectCollection newObjects, ITypeResolutionService typeResolver) at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObjectProvider.CreateGlobalObjectsForItem(ProjectItem item, GlobalObjectCollection oldObjects, GlobalObjectCollection newObjects, ITypeResolutionService typeResolver) at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObjectProvider.CreateGlobalObjects(Project project) at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObjectProvider.GetGlobalObjectsCore(Project project, Type baseType) at Microsoft.VisualStudio.Shell.Design.GlobalObjectProvider.GetGlobalObjects(Project project, Type baseType) at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects(Type baseType) at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects() at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetTypeFromGlobalObjects(String name, Boolean throwOnError, Boolean ignoreCase) at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError) at System.Resources.ResXDataNode.ResolveType(String typeName, ITypeResolutionService typeResolver) at System.Resources.ResXDataNode.GenerateObjectFromDataNodeInfo(DataNodeInfo dataNodeInfo, ITypeResolutionService typeResolver) at System.Resources.ResXDataNode.GetValue(ITypeResolutionService typeResolver) at System.Resources.ResXResourceReader.ParseDataNode(XmlTextReader reader, Boolean isMetaData) at System.Resources.ResXResourceReader.ParseXml(XmlTextReader reader) at System.Resources.ResXResourceReader.EnsureResData() at System.Resources.ResXResourceReader.GetMetadataEnumerator() at System.ComponentModel.Design.Serialization.ResourceCodeDomSerializer.SerializationResourceManager.GetMetadata() at System.ComponentModel.Design.Serialization.ResourceCodeDomSerializer.SerializationResourceManager.GetMetadataEnumerator() at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertiesFromResources(IDesignerSerializationManager manager, Object value, Attribute[] filter) at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration) 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)
|
This was causing lot of problems as we were not able to view the form. It took me 2 days to finally get the cause and find a resolution for the same.
Cause:
The cause for this is that while migrating, the existing resource files didn’t get migrated properly (I still need to figure out if this resource migration problem was due to incomplete migration by VS.NET or was due to our ignorance of warnings/errors given by VS.NET while migrating). We have data in format like:
<data name="lblName" xml:space="preserve">
<value>Rupreet</< SPAN>value>
< SPAN><data>
Now, if the previous resource file has some blank values something like:
<data name="lblName" xml:space="preserve"></< SPAN>data>
This will be invalid in the new schema for resources files. The value can be empty but the schema should be maintained. So the valid data with blank value should be
<data name="lblName" xml:space="preserve">
<value></< SPAN>value>
< SPAN></data>
Resolution:
In the resource file property, you need to add “ResXFileCodeGenerator” in the “Custom Tool” property. When you press enter, this tool runs and create a YourResourceFileName.Designer.cs file. With this, your resource file will contain new schema. If you get an error “Object reference not set to an instance” then this means that your data is not in proper format and the designer file will not be created. You first need to fix your data with the correct schema as I mentioned above and try running the tool again. When it saves properly with the desinger class creates, it means your resource file is in correct format. Now try opening your Forms, it should work! J