5

I am updating an old application built several years ago and the global namespace and, project.cs file, and the main form were all named as email2case_winForm

I wanted to change this (alongside rebuilding the application in more of an OOP way to make it more flexible, and to be able to re-use code), so changed the names to email2case

But now I am having trouble compiling because when reading the settings and properties of the project, those members cannot be found.

Here is an example of the code I am trying to use to read the properties.Settings:

XElement x = XElement.Load(email2case.Properties.Settings.Default.e2cConfigFile);

and the compiler error for that one is:

'email2case.email2case' does not contain a definition for 'Properties'

Here is how a class is reading from the global settings:

this.Url = global::email2case.Settings.Default.email2case_sforce_SforceService;

and the compiler error for that one is:

The type or namespace name 'Settings' does not exist in the namespace 'email2case' (are you missing an assembly reference?)

I have a hunch that the problem is caused by the definitions in app.Config and here it is:

<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="email2case.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
            <section name="email2case.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="email2case.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
      <email2case.Properties.Settings>
        <setting name="email2case_sforce_SforceService" serializeAs="String">
          <value>https://login.salesforce.com/servi...</value>
        </setting>
        <setting name="e2cConfigFile" serializeAs="String">
          <value>C:\email2case\data\e2cConfig.xml</value>
        </setting>
      </email2case.Properties.Settings>
      <email2case.Properties.Settings>
        <setting name="email2case_sforce_SforceService" serializeAs="String">
          <value>https://login.salesforce.com/serv...</value>
        </setting>
      </email2case.Properties.Settings>
    </applicationSettings>
    <system.serviceModel>
        <bindings/>
        <client/>
    </system.serviceModel>
    <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><userSettings>
        <email2case.email2case.Properties.Settings>
            <setting name="enableEWSTrace" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="attachmentsPathLocal" serializeAs="String">
                <value>C:\email2case\temp\</value>
            </setting>
            <setting name="eTracePath" serializeAs="String">
                <value>C:\email2case\Trace\</value>
            </setting>
            <setting name="ewsTraceKeepDays" serializeAs="String">
                <value>1</value>
            </setting>
        </email2case.email2case.Properties.Settings>
    </userSettings>
</configuration>

I don't want to go editing that without knowing exactly the right way to do it, so what code should I use to reference my properties and settings?

Or should I alter the way they are defined in the app.config?

Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148
  • 1
    do you see a .settings file in the project.What do you see when you goto Project -> Properties -> Settings in visual studio ? – gideon Jul 29 '15 at 10:59
  • @gideon: Turns out that after correctly changing the global namespace, saving, rebuilding, the correct reference for the properties is `Properties.` and NOT `email2case.Properties.` ... do you think I should add my own answer, or close/delete the question? – Our Man in Bananas Jul 29 '15 at 11:03
  • You should answer your question, add detail and accept the answer (the system will allow that after two days) – gideon Jul 29 '15 at 11:03
  • @gideon: Thanks I have added it, please would you take a look and see if it makes sense and would be helpful to others? – Our Man in Bananas Jul 29 '15 at 11:12
  • Yep it is :) Great job! – gideon Jul 29 '15 at 11:15

3 Answers3

12

The issue was caused by 2 problems:

  1. When you change the namespace, it needs to be done in the Application Settings instead of just going into the code and replacing old namespace with new namespace
  2. After incorrectly changing the namespace in the code, the namespace in the code was out of sync with the application settings, and app.config

The solution was to

  1. Change the namespace in the proper place (in the Project Properties > Application > default Namespace
  2. Clean, Rebuild, Save the project
  3. Refernce the settings and properties in code using the correct code.
    • in my case this was Properties. and NOT email2case.Properties. ...
Community
  • 1
  • 1
Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148
0

Place cursor in the place (namespace,method) which you want to change and then press F2 then a new window will open and just follow the instructions

renaming the methods or namespace manually will bring more errors because the project was already built so when we run a project visual studio automatically generated the designer code and change need to be done that file too

Hasiya55
  • 23
  • 7
  • This is a helpful tip, but please would you take some time to add some more information about how it would solve the problem, and what the problem was - then I can up-vote it. Being one sentence it should really be just a comment – Our Man in Bananas Jul 29 '15 at 11:20
0

I had the very same problem (after changing the casing of the namespace), and read this: https://stackoverrun.com/de/q/244400

In my case the problem was that %LocalAppData%\<old namespace> existed in the old casing and, even during development, the setting were read from that location. I removed the directory and everything returned to working order.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87