0
votes

I am working on a program in C# .NET 2010 using WinForms and am having difficulty inheriting the System.windows.Forms.DataVisualization.Charting.Chart class into a custom chart.

When I view the form in the Visual Studio designer, I get an error saying:

Could not find type 'ExpeView.ExpeDataChart'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.

The file ExpeDataChart.cs is part of this project, and whenever I compile and run the program, it works perfectly. This error only comes up in the designer view, making it impossible for me to edit the form through the GUI.

The file ExpeDataChart.cs looks like this (this is slimmed down, but gets the point across):

namespace ExpeView
{
    public class ExpeDataChart : Chart
    {
        public ExpeDataChart()
        {
            MouseMove += SampleMouseMove;
            MouseLeave += SampleMouseLeave;
            MouseDoubleClick += SampleDoubleClick;
            MouseDown += SampleMouseDown;
            MouseUp += SampleMouseUp;
            MouseEnter += SampleMouseEnter;
            MouseLeave += SampleMouseLeave;
            MouseWheel += SampleMouseWheel;
        }

        private void SampleMouseMove(object sender, MouseEventArgs e) { }
        private void SampleMouseLeave(object sender, EventArgs e) { }
        private void SampleDoubleClick(object sender, MouseEventArgs e) { }
        private void SampleMouseDown(object sender, MouseEventArgs e) { }
        private void SampleMouseUp(object sender, MouseEventArgs e) { }
        private void SampleMouseEnter(object sender, EventArgs e) { }
        private void SampleMouseWheel(object sender, MouseEventArgs e) { }
        private void SampleZoomIn(int x) { }
        private void SampleZoomOut() { }
    }
}

What would cause it to not properly load in the designer, but still load properly when compiling? The call stack of the error is:

ExpeView FormExpeView.Designer.cs Line:438 Column:1 at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

1
I was trying to quickly recreate the issue, but it seemed to work correctly. It looks like there may be an error in the Designer file of the form. Have You tried to remove the control from the form (in the code in FormExpeView.Designer.cs file)? After removing the control from the form, rebuild the project, verify that You can show the designer of the form and then add the control again through the designer.Lukasz M
I did do this and it worked properly. groverboy gave me a working solution though - put ExpeDataChart.cs into a separate project from the form.kingcoyote
In a test project, I added the control to the same project as the form is and the designer worked correctly. I suppose the issue was caused by something else (maybe some old code in the designer file), which might have been automatically resolved as a result of changing the control's location.Lukasz M
Using Visual Studio 2010 and WinForms? Did you extend Chart like I did, or another control? At one point, I gutted ExpeDataChart to just be a renamed Chart and it still didn't work. But, when I replaced it with a regular Chart, it did work. It seemed to very much not want to work with the extended ExpeDataChart until I moved it to another project.kingcoyote
I extended Chart class. I did it in two ways (by adding a simple class that inheriting from Chart and by adding a User Control derived from Chart). I was able to add both of those to the form using the designer. I used VS 2010 Express and a console project with WinForms form (butI suppose this should not make any difference in this case).Lukasz M

1 Answers

1
votes

Move the file ExpeDataChart.cs to a separate project, a library project. The new project can be part of the Visual C# solution, or a separate solution, e.g. CustomControls. Then add a reference to the library project to the project that uses the custom control. Now you should be able to edit the custom control using the visual designer.