Showing posts with label VS 2012. Show all posts
Showing posts with label VS 2012. Show all posts

Wednesday, December 11, 2013

Adding a simple custom section in App.config c#

In App.config: you need to set up a configSections / sectionGroup sections, then you can add your custom sections below appSettings:

xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="EpicSettings">
      <section name="EpicVersions" type="System.Configuration.DictionarySectionHandler"/>
    </sectionGroup>
  </configSections>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <appSettings>
    <add key="rootLevel" value="C:\Program Files (x86)\Epic"/>
    
    <add key="drFltr" value="Interconnect-*"/>
    <add key="DevVersion" value="Interconnect-DEV"/>

    <add key="CmdBldr" value="CommandBuilder.exe"/>
    <add key="CnfgEdt" value="ConfigEditor.exe"/>
    <add key="TrcVw" value="TraceViewer.exe"/>

    <add key="GnrlCnfg" value="\Web\App_Data\Config\General.config"/>

    <add key="WbSvPxyBldrSubDir" value="\Tools\"/>
    <add key="WbSvPxyBldr" value="WebServiceProxyBuilder.exe"/>

    <add key="PhsGenSvcSubDir" value="\Web\bin\"/>

  </appSettings>
  
  <EpicSettings>
    <EpicVersions>
      <add key="v7.9" value="Epic 2012"/>
      <add key="v8.1" value="Epic 2014"/>
    </EpicVersions>
  </EpicSettings>

</configuration>



In code:  Here is one way to access your custom section in the code:  Here we’re trying to determine the Epic Version based on if the directory path contains a string matching one of the config keys.

private string getEpicVersion(string vrsnpth)
        {
            string ret = string.Empty;
 
            var epicVersions = (ConfigurationManager.GetSection("EpicSettings/EpicVersions"as System.Collections.Hashtable)
                 .Cast()
                 .ToDictionary(n => n.Key.ToString(), n => n.Value.ToString());
 
            foreach (System.Collections.Generic.KeyValuePair<stringstring> vrsn in epicVersions)
            {
                if (vrsnpth.ToLower().Contains(vrsn.Key.ToLower()))
                {
                    ret = vrsn.Value;
                    break;
                }
 
            }
 
            return ret;
        }





Tuesday, September 18, 2012

Look what VS 2012 did to my VS 2010!

VS 2012 is useless to me for my work project.
What compiles fine in VS 2008 and VS 2010 throws up errors:

error CS1502: The best overloaded method match for 'System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)' has some invalid arguments

Oh and now getting the same error in VS 2010 where it was working before VS 2012 install!

Searching the online forums several developers having same issue.  Seems that some attributes and elements within the table element have to be removed in order for the project to compile again.

I've seeing a lot of "remove the runat='server' as working solutions.  This is unacceptable.  The tables are refreanced on server side.  This is a huge project with several developers writing code.

I uninstalled .NET runtime 4.5 and now both VS 2012 and VS 2010 are hosed.

Now stuck with using VS 2008 until I can hopefully repair the VS 2012 install so I can at least go back to using VS 2010.