views:

29

answers:

1

Hi

When i try to open my MainForm in Visual Studio in the designer, this error pops up instead of the designer of the Visual Studio.

Can't find the SubSonicService section of the application config file

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

It worked before and there are a lot of other Forms/Controls in the Project and they work. I also can build my project and run it without any problems, it seems just to be the designer.

My app.config has a section of SubSonic and i didn't change it so it should be correct because it worked before.

I use C# with Visual Studio 2005 and .net 2 with SubSonic 2, i can't switch, it's an existing project.

Has anyone a idea how to fix this?

A: 

I think you try to load a subsonic object in the constructor of your main form or any other custom control in it. This is a common error that happen with other objects that don't work within the designer. For this case there is a property DesignMode which you can check:

if (!DesignMode)
{
    Product p = new Product(1);
}

That said, I would suggest to not rely on the app.config to configure subsonic in windows forms projects. There are different ways to inject a provider into subsonic2 without using a app.config. In a web project there is always an web.config file that holds most config options for the whole project but in a windows forms app there are other challenges like:

  • changing connection string options (different hosts/users) and you probably don't want to store your password in the app.config (at least if you don't use single sign on).
  • if you use subsonic in a class library you have to add an subsonic service section to every winforms / console app that uses it.
  • runtime connection changes. Maybe you have a test and a production db that you wan't to connect to without closing the app and edit your app.config file.

Look at my answer here: http://stackoverflow.com/questions/968391/subsonic-dynamic-connections/968655#968655 how to do this.

(the code isn't from me but the original page is down)

This method works like a charm for me.

SchlaWiener