C # properties / settings not defined after changing project name and namespace

I am updating an old application made a few years ago and the global namespace and the project.cs file and the main form were named as email2case_winForm

I wanted to change this (along with rebuilding the application in more than an OOP way to make it more flexible and reusable) so changed the names to email2case

But now I have a compilation problem because when reading the settings and properties of the project, these members cannot be found.

Here is some sample code I'm trying to use to read properties. Settings:

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

      

and compiler error for this:

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

This is how the class is read from the global settings:

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

      

and compiler error for this:

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

I have a suspicion that the problem is caused by the definitions in app.Config

, but this:

<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 edit this without knowing exactly how to do it correctly and what code should I use to reference my properties and settings?

Or do I need to change the way it is defined in app.config ?

+3


source to share


3 answers


The problem was caused by two issues:

  • When changing the namespace, it needs to be done in the Settings app instead of just going into the code and replacing it old namespace

    withnew namespace

  • After changing the namespace in the code incorrectly, the namespace in the code was out of sync with the app settings and app.config


The solution was

  • Change the namespace to the desired location (in Project Properties> Application> Default Namespace
  • Clean, rebuild, save project
  • Refer to the settings and properties of the code with the correct code.
    • in my case it was Properties.

      also NOT email2case.Properties.

      ...
+7


source


Place the cursor in the location (namespace, method) 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 result in more errors as the project has already been built, so when we launch the visual studio of the project, the designer code is automatically generated and the change must be done with this file as well

+1


source


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

In my case, the problem was what %LocalAppData%\<old namespace>

existed in the old corpus and even during development the parameter was read from that location. I deleted the directory and everything was back up and running.

0


source







All Articles