Question

I'm getting designer error on code:

The Component i'm willing to define a List of properties for:

using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestProjectForProperty.Test
{
    public class MyTreeView : TreeView
    {
        private List<TypeDescriptorBase> _descriptorsAvailable = new List<TypeDescriptorBase>();

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public List<TypeDescriptorBase> DescriptorsAvailable
        {
            get { return _descriptorsAvailable; }
            set { _descriptorsAvailable = value; }
        }
    }
}

The Descriptor itself:

using System;

namespace TestProjectForProperty.Test
{
    [Serializable]
    public class TypeDescriptorBase
    {
        public string Name { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }
}

I am getting the following error if i try to use the component for example on a form and add any items on the property sheet or in the component's constructor to the DescriptorsAvailable property

Error 1 Invalid Resx file. Could not load type System.Collections.Generic.List`1[[TestProjectForProperty.Test.TypeDescriptorBase, TestProjectForProperty, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 which is used in the .RESX file. Ensure that the necessary references have been added to your project. Line 134, position 5. ...\visual studio 2010\Projects\TestProjectForProperty\TestProjectForProperty\Form1.resx 134 5 TestProjectForProperty

In the Resx file there is data field with base64 encoded stuff inside when this error is present.

I have been searching for an answer, but the best i got is to restart everything, it didn't help me, do you guys have any suggestions? I'm using .net 4 client and visual studio 2010

Was it helpful?

Solution 2

Put the MyTreeView and TypeDescriptorBase classes into another project and reference it from your GUI project will resolve the issues.

I'm not sure why exactly the problem occurs - I guess it has something to do with the way the serializing process is generating the base64 string for the DescriptorsAvailable Property. Maybe somebody else can give us some insight.

OTHER TIPS

In my experience, this is due to a change of version of a referenced library, or a change of the lib itself, which contains the backing type of a property you have defined in your user control. The solution is to "force" the visual studio designer to re-initialize it's designer code for that type, and not expect to retrieve a "canned" version of it from the .resx file of the control.

1) Delete the offending data section in the .resx file of your control. This will be a section in the xml of the .resx file associated with your user control, which has a node: <data></data> - the name attribute will be set to whatever you've named that object in the properties of whatever you added this type to. The <data>/data> section contains a base64 encoded string that is the encoded form of the name and version of the library the type comes from. This is where the problem ism, because it now contains an encoded version of the library and/or version number you are no longer referencing in order to include the type. Delete the entire <data>/data> section, from opening to closing tag, save the change and close the file. Now the "artifact" is gone.

2) Now find the place in the designer file for your control, where the type is instantiated; this is initialization code generated for you by visual studio, and it is the place that is expecting to load a "canned" definition of the type from the base64 encoded string contained within the .resx file. The line will look something like this:

this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(resources.GetObject("myCtrlFoo.MyPropertyFroo")));

...now just replace the resources.GetObjec call with the instantiation of a new instance of the appropriate type like so:

this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(new MyNamespaceFoo.MyTypeFoo()));

...now save the change to the file, close it, rebuild, and everything should now build & run OK.

I've struggled quite a bit with this; I have three user controls that all expose the same non-designer property, but for some reason, any change to two of the three would instantly cause the next build to fail with this same issue. This is in VS 2015.

I wound up having to add the following two attributes to the property that kept expanding in the resx file, and it hasn't occurred since. It works for me because they're not available in the designer anyway.

[Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

For me, this error occured when I used a custom class as a property for the user control. When I switched from property to traditional get- and set- methods, the error disappeared. I guess this is because properties are already compiled at design-time, so when you build the whole project, a new version of the custom class is compiled which is separate from the one of the control, and the reference is broken.

For me, with the custom class Inventory, all I had to do was to switch from this property-based approach:

public Inventory Resources {get;set;}

to this method-based approach:

private Inventory resources;
public Inventory getResources() { return resources; }
public void setResources(Inventory newResources) { resources = newResources; }

I hope this helps someone, as I've been spending some hours on figuring it out.

In my case I've got the error : "error MSB3103: Invalid Resx file. The specified module could not be found" executed in a light windows container based on mcr.microsoft.com/powershell instead of mcr.microsoft.com/windows:1909 (was working fine on 1909). The error was on a ressource icon that was compressed with PNG inside. It can be checked by opening the ressource on visual studio : Project > Properties > Ressources.resx, select icons, double click on the icon, check the end of the title that is either "..,BMP]" or "...,PNG]"). Updating the icon with an uncompressed format solve the "Invalid Resx file" issue.

I stumbled across this question today whilst looking for the solution to a similar issue.

Unfortunately none of the above worked for me, however my issue turned out to be that I had different versions of the .NET Framework for different projects. For example;

Project A - .NET Framework 4.7.2 Project B - .NET Framework 4

Where Project B was referencing Project A. Solution was simply to change the .NET Framework version of Project B to 4.7.2 (in my case) and hey presto the issue was resolved.

A shame Visual Studio doesn't provide a more helpful error message in this case, but something to look out for!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top