ApplicationSettings for DLL with WCF and Console Application - dll

My project consists of a web service (WCF) and a console application that uses a common library in other projects.
This library has ApplicationSettings.
With Console application, I only have to set:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MyProject.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
[...]
<applicationSettings>
<MyProject.Library.Properties.Settings>
<setting name="EnvironmentMask" serializeAs="String">
<value>RCT_</value>
</setting>
</MyProject.Library.Properties.Settings>
</applicationSettings>
[...]
</configuration>
I tried to do the same side Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="MyCompany.ConfigurationGroup">
<section name="SignedFileConfiguration" type="MyCompany.Web.SecureFileProxy.SignedFileConfigurationHandler, Net.MyCompany.Web" />
</sectionGroup>
<sectionGroup name="applicationSettings">
<section name="MyProject.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
[...]
<MyCompany.ConfigurationGroup>
<SignedFileConfiguration Secret="SecretKey!" PatternOfGeneratedUrl="http://www.myCompany.net/cgi/getFile.aspx?volume={0}&path={1}&token={2}&name={3}" ConfiguratorType="MyCompany.Web.SecureFileProxy.SignedFileConfiguration, Net.MyCompany.Web">
<Volumes>
<add Name="fallow" PhysicalPath="" />
</Volumes>
</SignedFileConfiguration>
</MyCompany.ConfigurationGroup>
<applicationSettings>
<MyProject.Library.Properties.Settings>
<setting name="EnvironmentMask" serializeAs="String">
<value>DEV_</value>
</setting>
</MyProject.Library.Properties.Settings>
</applicationSettings>
[...]
</configuration>
During the execution of the web service, I get an exception : System.Configuration.SettingsPropertyNotFoundException and the object MyProject.Library.Properties.Settings is empty
the only website which talk about that is https://littletalk.wordpress.com/2008/05/07/use-applicationsettings-in-web-application/ but it isn't enought for me.
I hope you could help me.
Thanks for your attention
Regards

I found the cause of this issue.
it's because I use log4net and it has an issue https://issues.apache.org/jira/browse/LOG4NET-398
I have to find a new way to do it.

Related

HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid

I have been trying to connect my ASP.NET Web Application (.NET framework) to my local SQL database but I've been getting the same error where it says that the "The configuration section 'connectionStrings' cannot be read because it is missing a section declaration" as seen in the picture below.
This my web.config code.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<connectionStrings>
<add name = "Milestone3"
connectionstring = "Data Source = (localdb)\MSSQLLocalDB;Initial Catalog=Milestone_2;Integrated Security=True"/>
</connectionStrings>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
I saw on other stack overflow questions that people deleted the .vs folder ad rebuilding the project but it still doesn't work. I also tried this but nothing happened
Open control panel
Click on “program” link (not uninstall programs)
Click “turn windows features on/off” link
Locate “Internet Information services IIS” in the pop up window and expand its node
Expand the “World Wide Web Service” node
Expand “Application Development Features” node
Check the check box of “ASP.NET”
Then click ok button
The <connectionStrings> node should be a child of <configuration>, not a child of <system.web>. Change it to this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name = "Milestone3" connectionstring = "Data Source = (localdb)\MSSQLLocalDB;Initial Catalog=Milestone_2;Integrated Security=True"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>

Add AdWordsApi keys to App.config

I an developing a Windows form Application using VB. My software will connect to a SQL Database and to a Google Adwords API. The problem is when I try to Add the keys for the Adwords Api in the App.config file I get the following error: "Configuration system failed to initialize: AdWordsApi configuration section not recognized". I have read some examples about hoy to fill my Appconfig file but nothing seems to work. Could you help me know the proper way to do it? I leave here my App.config file
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXX">
<section name="ReporteExcel.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXX" requirePermission="false"/>
</sectionGroup>
</configSections>
<AdWordsApi>
<add key="MaskCredentials" value="true"/>
<add key="EnableSoapExtension" value="true"/>
<add key="EnableGzipCompression" value="true"/>
<add key="IncludeUtilitiesInUserAgent" value="true"/>
<add key="ProxyServer" value=""/>
<add key="ProxyUser" value=""/>
<add key="ProxyPassword" value=""/>
<add key="ProxyDomain" value=""/>
<add key="DeveloperToken" value="XXXXXXXXXXXXXXXXX"/>
<add key="GeneralClientCustomerId" value="XXX-XXX-XXXX"/>
<add key="CanalDigitalClientCustomerId" value="XXX-XXX-XXXX"/>
<add key="BanamexClientCustomerId" value="XXX-XXX-XXXX"/>
<add key="AuthorizationMethod" value="OAuth2"/>
<add key="OAuth2ClientId" value="XXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"/>
<add key="OAuth2ClientSecret" value="XXXXXXXXXXXXXX-XXXXXXX"/>
<add key="OAuth2RefreshToken" value="1/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXX-X"/>
<add key="WebClientCustomerId" value="XXX-XXX-XXXX"/>
<add key="SkipReportHeader" value="true"/>
<add key="SkipReportSummary" value="true"/>
<add key="SkipColumnHeader" value="false"/>
</AdWordsApi>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<applicationSettings>
<ReporteExcel.My.MySettings>
<setting name="sqlConnectionStr" serializeAs="String">
<value>Data Source=192.168.2.1;Initial Catalog=CATALOG;User ID=ADMIN;Password=ADMIN;</value>
</setting>
</ReporteExcel.My.MySettings>
</applicationSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Google.AdWords" publicKeyToken="XXXXXXXXXXX" culture="neutral"/>
<bindingRedirect oldVersion="18.33.0.0" newVersion="18.34.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Google.Ads.Common" publicKeyToken="XXXXXXXXXXXXXX" culture="neutral"/>
<bindingRedirect oldVersion="3.17.0.0" newVersion="3.18.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
As it reads the file, the configSections act as a Table of Contents for the file
Try the following change and see if it will recognize it. taken from here
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXX">
<section name="ReporteExcel.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXX" requirePermission="false"/>
</sectionGroup>
<section name="AdWordsApi" type="System.Configuration.DictionarySectionHandler"/>
</configSections>

Asp.Net MVC Razor can not find my custom HtmlHelper helper method

I created a helper method for the HtmlHelper class:
namespace MyExampleApp.Infrastructure
{
public static class LanguageHelper
{
public static HtmlString GenerateLocalizedAnchor(this HtmlHelper helper, string language, string innerText)
{
//Code will go here...
}
}
}
I imported the namespace in the View:
#using MyExampleApp.Infrastructure;
I added the namespace to the web.config file in the Views folder:
<add namespace="MyExampleApp.Infrastructure"/>
Even added to the web.config in the root folder too. I read many topics on Stackoverflow, every answer were the same: add the namespace to the web.config in the View folder.
I have been searching for hours. I have restarted Visual Web Developer Express many-many times, cleaned, rebuilt the build. According to the found topics on StackOverflow, everything is "perfect" in my code, but the Razor view still does not find my helper method. What else should I do?
UPDATE
The web.config in the Views folder:
<?xml version="1.0"?>
<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.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="MyExampleApp.Infrastructure"/>
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
The using statements in the class of the custom helper method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
Also I switched the HtmlString return value to MvcHtmlString, but the Razor view still does not see it.
One problem I see is that your return type is an HtmlString. That should be changed to MvcHtmlString. I will be able to provide a better answer once you've posted the stuff requested.

All my view models have become dynamic on upgrading to MVC 4 (razor)

Can anyone help me rectify an issue. I've upgraded from MVC3 to MVC4 using NuGet method in Visual Studio 2012. Now all my views' View Models have become Dynamic even though I declare their type, none of the properties can be accessed through intellisense on the view...
So for example:
public class MyPageModel{
public string Test {get;set;}
}
My view:
#model MyPageViewModel
<div>
#Model.Test
</div>
Hovering over "Model" brings up "dynamic WebPage.Model".
Hovering over "Model.Test" brings up "dynamic expression. This operation will be resolved at runtime"
Among the other usual libraries, my project references version 2 of these:
System.Web.Razor , System.Web.WebPages, System.Web.WebPages.Razor
Am I missing a reference perhaps?
Also to add, if my Viewmodel is an IEnumerable
e.g.
#model IEnumerable<MyPageViewModel>
Hovering over the "MyPageViewModel" brings up "Validation (HTML5). Element 'MyPageViewModel' is not supported.
I first followed the advice on this page:
http://www.asp.net/whitepapers/mvc4-release-notes
that didn't solve it for me, so I followed another piece of advice and completely overwrote my web.config in my Views folder with this:
<?xml version="1.0"?>
<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.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<system.web>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
Which solved my issues.
Make sure your ~/Views/Web.config contains the below sections:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
check your web.config against what LovelyBananas posted. For me, it was also the web.config in the /Views folder. Same thing. It still had references to MVC 3.0.0.0 after i did a nuget install MVC4 install...

"'ViewData' is not declared." when using MVC4 Razor Views in Class Library

Looking the various different suggestions and recommendations, like this this I can't get working Razor Views in the Class Library. Non of the System.Web.Mvc.WebViewPage properties are accessable, even if it's configured as a page Base Type. Here is my web.config in the Class Library:
<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.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<system.web>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
</system.web>
</configuration>
Any ideas what else could be missing?