none
Why does my VSTO C#.NET project not let me examine application settings at run-time? RRS feed

  • Question

  • I have a project that uses application settings to store user input so that I can persist settings between sessions of Excel.  This works fine in the code, e.g.:

    Properties.Settings.Default.SelectedIndexQuantity

    However, when I try to examine the contents of any of the settings while my code is running I get a weird reference to "PropertyStore" and the following error if I use the Immediate Window to "?" an application setting:

    System.Windows.Forms.PropertyStore' does not contain a definition for 'Settings' and no extension method 'Settings' accepting a first argument of type 'System.Windows.Forms.PropertyStore' could be found (are you missing a using directive or an assembly reference?

    The only workaround I have found is to create a temporary string and assign the value I want to check to this in the code.  I can then examine the contents of the string... but this is very clunky indeed.

    • Moved by David Wolters Thursday, September 22, 2011 2:47 PM moving to a more appropriate forum (From:Excel IT Pro Discussions)
    • Moved by Martin_Xie Friday, September 23, 2011 7:04 AM Move it to VSTO Forum for better support. (From:Visual C# General)
    Thursday, September 22, 2011 10:30 AM

Answers

  • Hi Diksta,

    I figured out your problem. The problem is that you use the wrong namespace for the value. If you want to get the correct value, you must write the full experssion which includes the namespace because there exist another same properties number unser System.Windows.Forms namespace.

    You can change the experssion like:

    ?VSTOCheckAppSettingRuntime.Properties.Settings.Default.Test

    VSTOCheckAppSettingRuntime is my project namespace, you can replace with yours.

    Hope this can give you the hint and feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Diksta Wednesday, September 28, 2011 9:00 AM
    Wednesday, September 28, 2011 3:31 AM

All replies

  • show your code segment here.

    chanmm


    chanmm
    Friday, September 23, 2011 6:40 AM
  • I don't think a code segment is going to help... the problem is that I have snippets of code like this:

     

    //Get the default Member/ Location

    cbMember.SelectedItemIndex = Properties.

    Settings

    .Default.Member;

    ...so I can persist the state of controls between sessions.  This works fine, but when I try to examine the "Properties", i.e. look at application settings during run-time it doesn't work and comes up with this "PropertyStore" error.

    Remember this is a VSTO project.

     

     

    Friday, September 23, 2011 9:40 AM
  • Hi Diksta,

    Thank you for posting.

    I can't reproduce the scenario on my side, could you show me the reproducible step lists for us and share with us the project on the skydrive: http://skydrive.live.com/ 

    And please take a look at this thread to see whether it can help you:

    PropertyStore does not contain a definition for Settings

    http://www.pcreview.co.uk/forums/propertystore-does-not-contain-definition-settings-t3065738.html

    If this does not help you, I will do further research with your project and try to give you some suggestios or workarounds.

    Best Regards, 


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bruce Song Monday, September 26, 2011 1:18 AM typo
    Monday, September 26, 2011 1:18 AM
  • Okay, that link helped - that is exactly what my problem is.  It's just a shame that the OP didn't come back to confirm this so the problem has never been identified/ resolved.  I don't really want to post my code - it is far too long, but this is really, really easy to reproduce so here are the steps to do just that:

    - Create a new VSTO project targetting Excel 2010.
    - Add a Ribbon to the project, take the default name of Ribbon1.
    - Add a button to the ribbon, take the default name of button1.
    - Add a Form to the project, take the default name of Form1.
    - Add the following code to the click event of the Ribbon button:

     

    private void button1_Click(object sender, RibbonControlEventArgs

    e)

    {

        Form1 fForm = new Form1

    ();
        fForm.ShowDialog();
    }

    - Now add a setting to the project in the Properties page, Settings tab.  Call it Test and assign it a value of "Test".
    - Finally, add two break points to the code, one on the fFrom.ShowDialog(); line and one on the first brace after Form1_Load in the Form1 class.

    Now run the code and press the button.

    At the first breakpoint type this into the immediate window:

    ?Properties.Settings.Default.Test

    You will get the correct value, "Test".

    Now press F5 to run through to the next breakpoint and type in the same enquiry to the immediate window.  This time you get:

    'System.Windows.Forms.PropertyStore' does not contain a definition for 'Settings' and no extension method 'Settings' accepting a first argument of type 'System.Windows.Forms.PropertyStore' could be found (are you missing a using directive or an assembly reference?)

     

    Tuesday, September 27, 2011 11:05 AM
  • Just in case this is more difficult to reproduce than I thought I also posted it as a project to:

    https://skydrive.live.com/redir.aspx?cid=7ea534f76ee09ba8&resid=7EA534F76EE09BA8!237

    I guess you will still need to add the breakpoints to this though...

    Tuesday, September 27, 2011 11:12 AM
  • Hi Diksta,

    I figured out your problem. The problem is that you use the wrong namespace for the value. If you want to get the correct value, you must write the full experssion which includes the namespace because there exist another same properties number unser System.Windows.Forms namespace.

    You can change the experssion like:

    ?VSTOCheckAppSettingRuntime.Properties.Settings.Default.Test

    VSTOCheckAppSettingRuntime is my project namespace, you can replace with yours.

    Hope this can give you the hint and feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Diksta Wednesday, September 28, 2011 9:00 AM
    Wednesday, September 28, 2011 3:31 AM
  • Okay, that works, but I am not so sure about the explanation of why I have to use the namespace.  Anyway, my immediate problem is solved so thanks for your help.
    Wednesday, September 28, 2011 9:01 AM