How to setup a configSection in .net 4.0 - c#-4.0

I'm trying to setup configSection for a .net 4.0 project.
<configuration>
<configSections>
<section name="MonitorFldrSection"
type="System.Configuration.NameValueFileSectionHandler, System, Version=4.0.0.0"
allowLocation="true"
allowDefinition="Everywhere"/>
</configSections>
<MonitorFldrSection>
<add name="fldr1" value="C:\Temp" />
<add name="fldr2" value="C:\Projects" />
</MonitorFldrSection>
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
</configuration>
However, when I try to add a key, all I get for prompts are
comment or CDATA prompts
When I try to access in code
object obj = ConfigurationManager.GetSection("MonitorFldrSection");
I get this error: {"An error occurred creating the configuration section handler for MonitorFldrSection: Could not load file or assembly 'System, Version=4.0.0.0' or one of its dependencies. The system cannot find the file specified. (C:\Projects_4.0\NasImageIndexer\TestForm\bin\Debug\TestForm.exe.Config line 5)"}
Along with NameValueFileSectionHandler, I've also tried AppSettingsSection and DictionarySectionHandler.
What am I doing wrong?

Can you find this file in the location C:\Projects_4.0\NasImageIndexer\TestForm\bin\Debug\TestForm.exe.Config?
If not change the property for the config file
Build Action - Content
Copy to Output Directory - Copy Always
Edited:
This worked for me after adding public key token and change the name to key instead
<configuration>
<configSections>
<section name="MonitorFldrSection"
type="System.Configuration.NameValueFileSectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowLocation="true"
allowDefinition="Everywhere"/>
</configSections>
<MonitorFldrSection>
<add key="fldr1" value="C:\Temp" />
<add key="fldr2" value="C:\Projects" />
</MonitorFldrSection>
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
</configuration>

Related

Data Access Application Block Configaration settings

I am using DAAB 5.0 in my WCF application, I need to add the following code in my Web.Config for DAAB to work
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
</configSections>
<dataConfiguration defaultDatabase="defaultConnString" />
<connectionStrings>
<add name="defaultConnString" connectionString="..."
providerName="System.Data.SqlClient" />
</connectionStrings>
However in higher environament Web.Config is quto generated, So I am manually pasting the config section in the Web.Config
Is there any alternative to have config section in a differrent file?

Compilation errors when trying to use ServiceStack Razor plugin with cshrml at root of site

I am currently having some issues getting the ServiceStack Razor to render my page at the root of the site. I am encountering the following error
Compiler Error Message: CS0246: The type or namespace name 'ViewPage' could not be found (are you missing a using directive or an assembly reference?)
public class #__CompiledTemplate : ViewPage {
I just started on the site and here are the contents of the web.config and the razor pages
Here is the web.config file at the root of the website
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<buildProviders>
<add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" />
</buildProviders>
</compilation>
<httpRuntime targetFramework="4.5" />
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 (and above?) -->
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="ServiceStack.Html" />
<add namespace="ServiceStack.Razor" />
<add namespace="ServiceStack.Text" />
<add namespace="ServiceStack.OrmLite" />
<add namespace="FERNSWeb" />
</namespaces>
</pages>
</system.web.webPages.razor>
</configuration>
Here is the default.cshtml file at the root of the site
#inherits ViewPage
This is the body
and the _Layout.cshtml at the root of the site
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FERNS - #ViewBag.Title</title>
</head>
<body>
#RenderBody()
</body>
</html>
The intellisense does not colorize the "ViewPage" entry in the "#inherits ViewPage" line in the default.cshtml
And when i change the line to "#inherits ServiceStack.Razor.ViewPage", intellisense colorizes the ViewPage entry, but I get a exception this time and not a compilation error.
Exception Details: System.InvalidCastException: Unable to cast object of type 'Razor.__CompiledTemplate' to type 'System.Web.IHttpHandler'.
[InvalidCastException: Unable to cast object of type 'Razor.__CompiledTemplate' to type 'System.Web.IHttpHandler'.]
System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, VirtualPathFactoryManager virtualPathFactoryManager) +56
System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context) +264
System.Web.WebPages.WebPageHttpModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +89
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
The weird part is, if i move the Default.cshtml and the _Layout.cshtml file a Views folder I created for testing, the page renders just fine under the "/views" url. The Views folder does not have a web.config file in it.
Just solved the problem i was having above. I had to add the following to the root web.config file to have it work
<appSettings>
<add key="webPages:Enabled" value="false" />
</appSettings>
Not sure that I completely understand why though. Is the default value for "webPages:Enabled" different for the web.config under root and the web.config for folders? That is the only explanation I could think of for this one.

Error on trying to configure RavenDB in IIS mode

Following the steps in this tutorial, the first item of "Setting up with IIS 7.5" after clicking on "Modules" in inetmgr, the following error occurs:
Full image: http://i.stack.imgur.com/QCM4s.png
Web.config in RavenDB
<configuration>
<appSettings>
<add key="Raven/DataDir" value="~\Data"/>
<add key="Raven/AnonymousAccess" value="Get"/>
</appSettings>
<system.webServer>
<handlers>
<add name="All" path="*" verb="*" type="Raven.Web.ForwardToRavenRespondersFactory, Raven.Web"/>
</handlers>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
<runtime>
<loadFromRemoteSources enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Analyzers"/>
</assemblyBinding>
</runtime>
</configuration>
applicationHost.config
http://pastebin.com/UJTJfB9f
Try
For a few attempts, I tried to change
this..
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
to this..
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
Results
When trying to access "in inetmgr Modules worked!"
However RavenDB Studio does not work.
The following image:
Config Error
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File
\\?\C:\Users\Riderman\RavenDB-Build-960\Web\web.config
Check your server web.config and change overrideModeDefault from Deny to Allow.
<configSections>
<sectionGroup name="system.webServer">
<section name="handlers" overrideModeDefault="Deny" />
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
You can also manage sections on web server level (just select the Server in the left pane) in your IIS management console and then select "Feature Delegation":
As you see in the picture above all the features are Read/Write. Currently on my machine the Modules feature is Read Only, so I'd need to change it to Read/Write - in the right hand pane in Set Feature Delegation just click on Read/Write...

Devexpress aspx controls not styling after publish to different server

I have a few Devexpress aspx controls on a website that look fine on our development server. When I publish the exact same files to the live server, everything works, but none of the controls have any styling.
I have checked the site, in the IE dev tools, and it seems to have a link to only 1 DXR.axd while the dev server has a link to 3. Each one is different.
Don't really know where to begin checking as everything seems identical on both servers, including web.config, see below:
<?xml version="1.0"?><configuration>
<configSections>
<sectionGroup name="devExpress">
<section name="settings" type="DevExpress.Web.ASPxClasses.SettingsConfigurationSection, DevExpress.Web.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
<section name="compression" type="DevExpress.Web.ASPxClasses.CompressionConfigurationSection, DevExpress.Web.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
<section name="themes" type="DevExpress.Web.ASPxClasses.ThemesConfigurationSection, DevExpress.Web.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
<section name="errors" type="DevExpress.Web.ASPxClasses.ErrorsConfigurationSection, DevExpress.Web.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings>
<add name="testConnectionString" connectionString="Server=<test>;User ID=root;Password=password;Database=test" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="DevExpress.Web.ASPxScheduler.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="DevExpress.Web.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="DevExpress.XtraScheduler.v10.2.Core, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="DevExpress.Data.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="DevExpress.Web.ASPxEditors.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="DevExpress.Web.ASPxGridView.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="DevExpress.Web.ASPxPivotGrid.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="DevExpress.PivotGrid.v10.2.Core, Version=10.2.8.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/></assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<httpModules>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule"/>
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v10.2, Version=10.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule"/>
</modules>
</system.webServer>
<devExpress>
<settings rightToLeft="false"/>
<compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="false"/>
<themes enableThemesAssembly="true"/>
<errors callbackErrorRedirectUrl=""/>
</devExpress>
</configuration>
Deploy the "ASPxThemes" assembly (DevExpress.Web.ASPxThemes.vXX.Y.dll) within the server GAC or WebSite Bin folder.
This assembly stores required DevExpress ASP.NET Themes resources.

SubSonic - Generated Classes have the following error - the type or namespace name does not exist in KimDal

Im trying to generate my dal and this works but when i check my code in visual studio 2008 i get this message "the type or namespace name does not exist in KimDal"
Im using sql expreess 2005, full version of vs2008, and i setup a new c# 2.0 website.
I installed the 2.1 installer for subsonic, add added it to my external tools, i added a refernce to the dll which added it and other dlls to my bin folder.
I also addeded references to system.web and system.configuration as i saw somehwere that this resolved someone elses issue.
My config is below, is the error im geting normal within intelisense when i look at the class, or do i need to fix something and how do i fix it.
<configuration>
<configSections>
<section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" requirePermission="false"/>
</configSections>
<appSettings/>
<connectionStrings>
<!-- Development connection string -->
<add name="kimWebApp" connectionString="Data Source=7NQ384J\SQLExpress;Initial Catalog=kim2;Integrated Security=True"/>
</connectionStrings>
<SubSonicService defaultProvider="kimWebAppProvider">
<providers>
<clear/>
<add name="kimWebAppProvider" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="kimWebApp" generatedNamespace="KimDal"/>
</providers>
</SubSonicService>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="false" defaultLanguage="c#">
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
<system.codedom>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
</system.webServer>
</configuration>
Dont worry i now have this working, and was able to generate the code, to do so, i basically had to do the following.
Create a webconfig that looks like this
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" allowDefinition="MachineToApplication" restartOnExternalChanges="true" requirePermission="false"/>
</configSections>
<appSettings/>
<connectionStrings>
<add name="kimconnection" connectionString="Data Source=7NQ384J\SQLExpress;Initial Catalog=kim2;Integrated Security=True;"/>
</connectionStrings>
<SubSonicService defaultProvider="kimAppProvider">
<providers>
<clear/>
<add name="kimAppProvider" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="kimconnection" generatedNamespace="kimdata"/>
</providers>
</SubSonicService>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" defaultLanguage="C#">
<buildProviders>
<add extension=".abp" type="SubSonic.BuildProvider, SubSonic"/>
</buildProviders>
<assemblies>
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
<add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<pages>
<controls>
<add assembly="SubSonic" namespace="SubSonic" tagPrefix="subsonic"/>
</controls>
</pages>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
I copied the config file from my installation of subsonic C:\Program Files\SubSonic\SubSonic 2.1 Final\src\SubSonicCentral
Changed for my needs, i then added the reference to subsonic which included all the dlls below.
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.ObjectBuilder.dll
MySql.Data.dll
System.Data.SQLite.dll
subsonic.dll

Resources