I have created a basic feature file and trying to execute my first program. I have installed all mandatory packages through NuGet.
Error received :
Error The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly.
System.Exception: Error when reading project file. ---> System.Configuration.ConfigurationErrorsException: Unrecognized element 'unitTestProvider'.
at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
at System.Configuration.ConfigurationSection.DeserializeSection(XmlReader reader)
at TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler.CreateFromXml(String xmlContent)
at TechTalk.SpecFlow.Configuration.ConfigurationLoader.Load(SpecFlowConfiguration specFlowConfiguration, ISpecFlowConfigurationHolder specFlowConfigurationHolder)
at TechTalk.SpecFlow.Generator.Configuration.GeneratorConfigurationProvider.LoadConfiguration(SpecFlowConfiguration specFlowConfiguration, SpecFlowConfigurationHolder specFlowConfigurationHolder)
at TechTalk.SpecFlow.Generator.Configuration.GeneratorConfigurationProviderExtensions.LoadConfiguration(IGeneratorConfigurationProvider configurationProvider, SpecFlowConfigurationHolder configurationHolder)
at TechTalk.SpecFlow.Generator.Project.ProjectReader.ReadSpecFlowProject(String projectFilePath, String rootNamespace)
--- End of inner exception stack trace ---
at TechTalk.SpecFlow.Generator.Project.ProjectReader.ReadSpecFlowProject(String projectFilePath, String rootNamespace)
at TechTalk.SpecFlow.Generator.Project.MSBuildProjectReader.LoadSpecFlowProjectFromMsBuild(String projectFilePath, String rootNamespace)
at SpecFlow.Tools.MsBuild.Generation.SpecFlowProjectProvider.GetSpecFlowProject()
at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTaskExecutor.Execute()
at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() specflowFramework
my app.config looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<specFlow>
<language feature="en-US" />
<unitTestProvider name="MSTest" />
</specFlow>
</configuration>
The unit test providers are not configured anymore in the app.config with SpecFlow 3. You have to use the appropriate NuGet package. Doc link: https://docs.specflow.org/projects/specflow/en/latest/Guides/UpgradeSpecFlow2To3.html#changes-to-how-unit-test-providers-are-configured
In your case, you have to add the SpecFlow.NUnit package to your project and adjust your app.config to
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<specFlow>
<language feature="en-US" />
</specFlow>
</configuration>
The list of the correct NuGet package depending on your unit test runner is: https://docs.specflow.org/projects/specflow/en/latest/Installation/Unit-Test-Providers.html
Full disclosure: I am a developer and maintainer of SpecFlow and SpecFlow+
Related
I want to create a simple section without writing any class by myself, I have read other posts and tried building my own section but it throws an exception of System.InvalidCastException when I try to get my section. Could anyone tell me how I can solve it? thanks!
Exception message:
An unhandled exception of type 'System.InvalidCastException' occurred in HttpServer.exe
Additional information: Unable to cast object of type 'System.Configuration.KeyValueInternalCollection' to type 'System.Configuration.AppSettingsSection'.
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="extensions" type="System.Configuration.AppSettingsSection" />
</configSections>
<extensions>
<add key=".gif" value="image/gif"/>
<add key=".png" value="image/png"/>
<add key=".jpg" value="image/jpeg"/>
</extensions>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
C# code:
AppSettingsSection section = (AppSettingsSection)ConfigurationManager.GetSection("extensions");
Console.WriteLine(section.Settings[".gif"].Value.ToString());
Change the System.Configuration.AppSettingsSection to System.Configuration.NameValueSectionHandler and get the value by
System.Collections.Specialized.NameValueCollection
I receive the following error from a Windows Service application
System.Net.WebException = {"An exception occurred during a WebClient request."}
-2146233079
InnerException = {"Configuration system failed to initialize"}
The same code on a Console application works fine.
The Service file has not setup Security on "Local Service" (in my test environment)
Could you point me out what could cause the error and how to solve it?
Try
Using client As New Net.WebClient
Dim reqparm As New Specialized.NameValueCollection
reqparm.Add("DeviceId", deviceId)
reqparm.Add("StatusCode", statusCode)
reqparm.Add("Type", "printer")
reqparm.Add("Message", msg)
Dim responsebytes = client.UploadValues("http://xxx.xxx.com/api/notification", "POST", reqparm)
Dim responsebody = (New Text.UTF8Encoding).GetString(responsebytes)
End Using
Catch ex As Exception
'do nothing
End Try
my App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<configSections>
<section name="app" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<app>
<add key="version" value="0.0.1"/>
</app>
</configuration>
The problem was in the App.config file. This the correct version, only one instance of <configSections> and should be the first element after <configuration>.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="app" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<app>
<add key="version" value="0.0.1"/>
</app>
</configuration>
Is it possible to split the configuration for an enterprise library block into multiple files?
For example: I have three assemblies and one hosting project. I want to store the entlib v6 Exception Handling Application Block (EHAB) configuration for each assembly in a separate config file located in the particular assembly.
The hosting project references the three assemblies:
assembly_X
ehabX.config
assembly_Y
ehabY.config
assembly_Z
ehabZ.config
Hosting project
using ehabX.config
using ehabY.config
using ehabZ.config
I already tried the following:
App.config in the hosting project:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource>
<sources>
<add name="ehabX" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabX.config" />
<add name="ehabY" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabY.config" />
<add name="ehabZ" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" filePath="ExceptionHandling\ehabZ.config" />
</sources>
<redirectSections>
<add sourceName="ehabX" name="exceptionHandling" />
<add sourceName="ehabY" name="exceptionHandling" />
<add sourceName="ehabZ" name="exceptionHandling" />
</redirectSections>
</enterpriseLibrary.ConfigurationSource>
</configuration>
ehabX.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Swallow NotImplementedException">
<exceptionTypes>
<add type="System.NotImplementedException, mscorlib" postHandlingAction="None" name="NotImplementedException"/>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
ehabY.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
</configSections>
<exceptionHandling>
<exceptionPolicies>
<add name="Swallow ArgumentException">
<exceptionTypes>
<add type="System.ArgumentException, mscorlib" postHandlingAction="None" name="NotImplementedException"/>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
The ehabZ.config is omitted.
Using the EHAB with the policy "Swallow NotImplementedException" works fine. But if I try to use the policy "Swallow ArgumentException" defnied in ehabY.config I get this error message:
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException: The policy with name 'Swallow ArgumentException' cannot be found. Exception handling aborted.
Any suggestions?
Unfortunately, there is nothing out of the box that will let you merge multiple configuration sources into one configuration set.
I think you can probably do what you want but you will have to do some coding. You'll need to read in the appropriate configuration sources and create a custom IConfigurationSource that will merge them all. Additive merge of different config sources? has an example of a MergeConfigurationSource that could help you.
I have duplicate entries in my log file for NServiceBus and I'm concerned this means I'm not starting it up correctly.
eg:
2012-03-21 10:44:37.9820|WARN|NServiceBus.Licensing|No valid license
file was found. The host will be limited to 1 worker thread.
2012-03-21 10:44:37.9820|WARN|NServiceBus.Licensing|No valid license
file was found. The host will be limited to 1 worker thread.
2012-03-21 10:44:38.0610|WARN|NServiceBus.Utils.MsmqUtilities|Queue
spy\private$\error does not exist.
2012-03-21 10:44:38.0610|WARN|NServiceBus.Utils.MsmqUtilities|Queue
spy\private$\error does not exist.
My config looks like this:
Configure.With()
.DefiningCommandsAs(t => typeof(ICommand).IsAssignableFrom(t))
.DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t))
.DefiningMessagesAs(t => typeof(IMessage).IsAssignableFrom(t))
.Log4Net<NlogAppenderForLog4Net>(a => { })
.NinjectBuilder(Kernel)
.XmlSerializer()
.MsmqTransport()
.DefineEndpointName("subscriber.input")
.IsTransactional(true)
.PurgeOnStartup(false)
.MsmqSubscriptionStorage("subscriber")
.UnicastBus()
.LoadMessageHandlers()
.ImpersonateSender(false)
.CreateBus().Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());
and app.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" requirePermission="false" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Publisher.Events" Endpoint="publisher.input" />
<add Messages="Publisher2.Events.Message, Publisher2.Events" Endpoint="publisher2.input" />
</MessageEndpointMappings>
</UnicastBusConfig>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
</runtime>
</configuration>
The NServiceBus profiles configure their own logging by default. You need to implement IWantCustomLogging to tell NSB that you're setting up logging your self.
Sample:
http://docs.particular.net/samples/logging/hostcustom/
I'm getting the following exception when I try to call
var log = LogManager.GetLogger(this.GetType());
A first chance exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll
An unhanded exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll
Additional information: Failed obtaining configuration for Common.Logging from configuration section 'common/logging'.
This is a .NET 4 application with references to
log4net.dll
Common.Logging.dll
Common.Logging.log4net.dll
my app.config has the following:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="ALL" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
</configuration>
I'm trying to call like so:
var log = LogManager.GetLogger(this.GetType());
log.Debug(m => m("testing"));
What am I missing?
It runs ok if you remove element startup from your config.
EDIT: Instead of removing, just move the startup element after configsections.