In my application i have configured the Trace listener as below
"HelloWorld" is my AssemblyName and Namespace
<system.diagnostics>
<sources>
<source name="DebugCategory" switchName="DebugSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<remove name="Default"/>
<!-- Add the listeners below -->
<add name="LogFile"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="Console" type="System.Diagnostics.ConsoleTraceListener" initializeData="true"/>
<add name="LogFile" type="HelloWorld.Diagnostics.FileLogTraceListener, HelloWorld" initializeData="HelloWorld.log" traceOutputOptions="DateTime" cycle="Month"/>
</sharedListeners>
While creating an installer using WIX, in my WIX file i will make the Target exe file from "HelloWorld.exe" to "MyWorld.exe" as below
<Component Id="MyWorld.exe" Guid="*">
<File Id="MyWorld.exe" Name="MyWorld.exe"
DiskId="1" Source="HelloWorld.exe" />
<Shortcut Id="HelloWorld.menu.exe" Name="Hello world application" Directory="McnMenu" Advertise="yes" WorkingDirectory="INSTAL32LLOCATION" />
</Component>
Since there is change in the EXE name, Tracelistener is not creating a log file.
Target name should be "Myworld.exe", If i revert the File element to
<File Id="HelloWorld.exe" Name="HelloWorld.exe" />
it works well
Can any one help me.
In this line of your .config file:
<add name="LogFile" type="HelloWorld.Diagnostics.FileLogTraceListener, HelloWorld" initializeData="HelloWorld.log" traceOutputOptions="DateTime" cycle="Month"/>
You have type="HelloWorld.Diagnostics.FileLogTraceListener, HelloWorld". That is a reference to a class in an assembly. The assembly name (the name of the file) is the part after the comma. Therefore your .config file requires the assembly (the executable in your case) to be named "HelloWorld".
To fix you can either leave the file name HelloWorld.exe (as you found) or change the .config file like so:
<add name="LogFile" type="HelloWorld.Diagnostics.FileLogTraceListener, MyWorld" initializeData="HelloWorld.log" traceOutputOptions="DateTime" cycle="Month"/>
Notice the MyWorld in the type after the comma.
Related
I am creating a form where I want to save a list of values to My.Settings. In the form, changes will be made to the list and when I close the form, the updated list will be saved to the settings. The next time I start the form my list will get the values from My.Settings.
This is what I have done so far.
To load the list from the settings:
Dim fl As New List(Of String)
For Each Item As String In My.Settings.foodlist
fl.Add(Item)
Next
And then to save the list into settings on closing the form:
My.Settings.foodlist.Clear()
For Each Item As String In fl
My.Settings.foodlist.Add(Item)
Next
My.Settings.Save()
Form1.Close()
In my project settings, I have defined foodlist as a system.collection.specialized.stringcollection. The scope is set to user, and the value is currently blank.
However, when I run, I receive an error which says System.Configuration.ConfigurationErrorsException: 'Configuration system failed to initialize'
ConfigurationErrorsException: Unrecognized configuration section system.diagnostics. (C:\Users\samsj\Downloads\EatWhat_webversion\WinFormsApp_22Feb\bin\Debug\net6.0-windows\EatWhat_webver.dll.config line 5)
In particular, the line that seems to have an issue is
Return CType(Me("foodlist"), Global.System.Collections.Specialized.StringCollection)
What am I doing wrong?
I managed to solve this after looking through suggestions from another forum. I went to my dll.config file and deleted the entire system.diagnostics code:
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
I have absolutely no idea why deleting this code works, since I assumed that this is a default code.
I using Vb.net , FW: Net5
This is my app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectString" value="DB/Sample.db3" />
</appSettings>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
I install "System.Configuration.ConfigurationManager" from Nuget
I had try get config as:
Dim str = System.Configuration.ConfigurationManager.AppSettings("ConnectString")
But it occur exception error:
Configuration system failed to initialize
How can read app.config in VB Net5?
I tried using an app.config file in a .NET 5.0 app and I got the same exception. Unlike you, I looked a bit further and saw that it also said that it encountered an unknown section, i.e. system.diagnostics. I then commented out the <system.diagnostics> element in my config file and it worked as expected. I'm not sure what you would do if you actually needed to use that section but it doesn't look like you do so it shouldn't be a problem to comment it out or delete it.
I am working on a web application. the Web.config file is set to NeverOverwrite (=yes) in its initial installation. Now i need to add DBproviderfactories like below. Can i add this entire block using XmlFile in a patch.msp? I do not want to write a custom action. All I need is to add this block in the web.config. Any suggestion here is appreciated.
<system.data>
<DbProviderFactories>
<!-- Remove in case this is already defined in machine.config -->
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="Oracle Data Provider for .NET" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
Sample: Maybe try this:
https://github.com/glytzhkof/WiXUpdateXmlFile
Below is the gist of it - please use the sample above for testing. The markup below is just for illustration.
Set the XML file both permanent and never overwrite.
See inline instructions in the sample above for testing.
Check what happens on uninstall - this markup will remove the entries it added.
<!-- Set app.config permanent and never overwrite to yes -->
<Component Feature="ProductFeature" NeverOverwrite="yes" Permanent="yes">
<File Source="app.config" />
</Component>
<!-- The XML update -->
<!-- Use a NEW GUID here, do not go live with this one -->
<Component Id="XmlFileUpdate" Guid="{00000000-0000-0000-0000-7405EED51B57}" Feature='ProductFeature'>
<!--Create New Element-->
<util:XmlFile Id='XmlSettings1' File='[INSTALLFOLDER]app.config' Action='createElement' Name='MyConfig' ElementPath='//configuration' Sequence='1' />
<!--Set New Value-->
<util:XmlFile Id='XmlSettings2' File='[INSTALLFOLDER]app.config' Action='setValue' Name='newVersion' Value='6.6.8' ElementPath='//configuration/MyConfig' Sequence='2' />
<!--Set New Value-->
<util:XmlFile Id='XmlSettings3' File='[INSTALLFOLDER]app.config' Action='setValue' Name='Server' Value='Pusevov' ElementPath='//configuration/MyConfig' Sequence='3' />
<!--Update Existing Value, Existing Element-->
<util:XmlFile Id='XmlSettings4' File='[INSTALLFOLDER]app.config'
Action='setValue' Name='newVersion' Value='7.7.7' ElementPath='//configuration/ExistingConfig/bindingRedirect' Sequence='4' />
<CreateFolder />
</Component>
</Directory>
</Directory>
Link:
Added new application setting to app.config but MSI won't install it (doesn't overwrite)
My solution exits out of 3 Projects:
SP_Class_Library contains my EF model
SP_Control_Library is a class library that contains all my custom and
user controls
SP_EF_TEST is my Form Application
I created a custom control cc_User_DropDown with the following code
Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
LoadUsers()
End Sub
Private Sub LoadUsers()
Dim UserList As List(Of SP_User) = Nothing
UserList = (From c In ent.SP_User
Where c.usr_Active = True
Select c
Order By c.usr_Name).ToList
Dim blank As New SP_User
blank.usr_ID = 0
blank.usr_Name = "Please select a user..."
UserList.Insert(0, blank)
Me.DisplayMember = "usr_Name"
Me.ValueMember = "usr_ID"
Me.DataSource = UserList
End Sub
The problem comes when I try and add the custom control to either u_Users or Form1 I get the error:
If I comment the code and build I can add the control, but as soon as I uncomment the code and build I get the following:
I have tried suggestions that say I must add the app.config to all the projects, Copy the connectionstring to all the .config files and remove the .config file from the dll and add it to the Form Application but it does not work.
Here is my app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<connectionStrings>
<add name="SPEntities" connectionString="metadata=res://*/SP_Model1.csdl|res://*/SP_Model1.ssdl|res://*/SP_Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost\SPDEV;initial catalog=SP;persist security info=True;user id=sa;password=xxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
I have a WCF REST service that exposes a method in class GreetService:
[ServiceContract]
public class GreetService
{
[WebGet(UriTemplate = "greet/{name}")]
public String GreetName(string name)
{
return "Hello " + name;
}
}
Also, I registered a route in Global.asax:
RouteTable.Routes.Add(new ServiceRoute("GreetService", new WebServiceHostFactory(), typeof(GreetService)));
Now when i run this directly from visual studio, I am able to leverage the UriTemplate and invoke this method using a GET call to
http://localhost:5432/GreetService/greet/JohnDoe
However, after deploying this to IIS7 by creating a Greet.svc file for it, I am observing the following behavior:
I can call http://localhost:5432/Greet.svc and it says that a service has been created
I can point wcftestclient to http://localhost:5432/Greet.svc?wsdl to generate a test client which can call GreetName() directly
However, I can't call http://localhost:5432/Greet.svc/GreetService/greet/JohnDoe nor http://localhost:5432/Greet.svc/greet/JohnDoe although I expected to be able to since I specified an empty relative endpoint address in the corresponding web.config file prior to hosting it in IIS7.
Any ideas why the WebGetAttribute is not working in IIS? Or is there something else I am doing wrong?
EDIT:
This is the ServiceModel part of my web.config file which resides in the directory that IIS uses:
<system.serviceModel>
<!-- <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> -->
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
EDIT 2: For completeness' sake here is my full web.config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule,
System.Web, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*" path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler,
System.Web, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
<system.serviceModel>
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>-->
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
If you've defined your route to be:
new ServiceRoute("GreetService", .....
then you should be able to call your service at
http://localhost:5432/YourVirtualDirectory/GreetService/greet/JohnDoe
and if your web app is deployed to your IIS root (not in a virtual directory), that would be:
http://localhost:5432/GreetService/greet/JohnDoe
When defining a ServiceRoute, that's done to get rid of having to specify the Greet.svc file, really - the ServiceRoute entry already contains all the information IIS needs to instantiate your service and call it - no need for having the *.svc file involved in your URL (the svc file basically contains the same info your ServiceRoute entry has).
Change the line in your global.asax.cs to read:
RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(GreetService)));
and put the following in your web.config right under the root <configuration> node:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule,
System.Web.Routing, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*" path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler,
System.Web, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
(do make sure you're using the right .NET version) and see what that does for you.
NOTE: please post the web.config, at least the system.servicemodel part.
You normally use either the Route-based configuration or a .svc file, not both, but that's orthogonal to your problem. FWIW, you should be able to kill the .svc file once you get the service working and just use the route.
Since you're able to generate WSDL and call it, that sounds like you might not have webhttp as an endpoint behavior?
Make sure you have an endpoint behavior defined like this (can be a diff name of course)
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
and then make sure your service endpoint includes behaviorConfiguration="webHttpBehavior"
The problem is machine config missing the following section
<configSections>
<sectionGroup name="system.serviceModel" type="System.ServiceModel.Configuration.ServiceModelSectionGroup, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="standardEndpoints" type="System.ServiceModel.Configuration.StandardEndpointsSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</sectionGroup>
</configSections>
Add it on top of web.config (after the opening tag of <configuration> ) should fix this problem.