Daily Usage Issues

problem with app.config file

Started by 4rchie on 16,382 views

I have a code that relies on a specific app.config file. The test project contains some tests that check the code which read the appp.config. I do have the config file prepared but I have no clue how to tell NCrunch to use that specific app.config while testing that specific assembly. Any clues how can I do that??

Regards
4rchie
Hi 4rchie,

Thanks for posting. NCrunch should resolve your app.config file in the same way that other test runners do. Do you have any interesting build steps (i.e. a post build event?) that may be needed as part of preparing this config? Note that you can have a look at the workspace NCrunch used to run your tests by right clicking on a test and choosing 'Browse to workspace used for selected test'.

Cheers,

Remco
I have nothing in the post build event.

The code I'm trying to test is:

public static MyServersCollection MyServers
{
get
{
var section = (MyConfigurationSection)ConfigurationManager.GetSection("myConfiguration");
return section != null ? section.MyServers : null;
}
}

In a brief, I have some classes that enhance my app.config.

The test that uses that is not executed - black dot - so I cannot do Browse to workspace used for selected test. In NCrunch Tests that particular test is having Running (First time run) status for ages. Im using the latest NCrunch. Any ideas for me?

Regards,
4rchie


update: I was missing a

<configSections>
<section name="myConfiguration" type=...../>
</configSections>

part in the app.config After adding that the tests are executed and.... fail due to some other error but I hope I'll find that soon.

Edited

Ok - I don't think this is a problem related to your configuration ... something else is going on.

Is the test ignored in the Tests Window? Or does it show with a green tick?
Test is not ignored. It runs now (after adding missing configSections in the app.config) but it fails. Funny thing is that it runs under the resharper runner but it fails under ncrunch (with an error like below):



SetUp : System.Configuration.ConfigurationErrorsException : An error occurred creating the configuration section handler for liderConfiguration: 'DefaultValue' property specified was not found. (k:\ncrunch\6040\43\Lider2.Configuration.Tests\bin\Debug\Lider2.Configuration.Tests.dll.config.NUnitTestFramework line 7)
----> System.Reflection.CustomAttributeFormatException : 'DefaultValue' property specified was not found.
----> System.Reflection.CustomAttributeFormatException : 'DefaultValue' property specified was not found.
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Lider2.Configuration.LiderConfiguration.get_LiderServers() in k:\ncrunch\6040\33\Lider2.Configuration\LiderConfiguration.cs:line 33
at Lider2.Configuration.Tests.LiderConfigurationTests.Setup() in k:\ncrunch\6040\43\Lider2.Configuration.Tests\LiderConfigurationTests.cs:line 18
--CustomAttributeFormatException
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimePropertyInfo property, RuntimeType caType)
at System.Reflection.RuntimePropertyInfo.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.InternalGetCustomAttributes(PropertyInfo element, Type type, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit)
at System.Configuration.ConfigurationElement.CreateConfigurationPropertyFromAttributes(PropertyInfo propertyInformation)
at System.Configuration.ConfigurationElement.CreatePropertyBagFromType(Type type)
at System.Configuration.ConfigurationElement.PropertiesFromType(Type type, ConfigurationPropertyCollection& result)
at System.Configuration.ConfigurationElement.get_Properties()
at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
at System.Configuration.ConfigurationElementCollection.OnDeserializeUnrecognizedElement(String elementName, XmlReader reader)
at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
at System.Configuration.ConfigurationSection.DeserializeSection(XmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
--CustomAttributeFormatException
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)

Edited

Ahh.. are you using named attribute parameters anywhere within your test?

There is a known problem in this area that I'm working on at the moment :)
I do....... :(

so problem solved - in a way :)

I'll wait for the new version then.

Thanks for your help.

Regards,
4rchie
Hi,

I'm experiencing the same problem - any progress on Named Parameters used in attributes?

--larsw
Sorry, a fix is still in progress!
Hi again,

Ok, thanks for the feedback.

For other people struggling with ConfigurationElement-derived classes; It's possible to override the InitializeDefault() method and set the default values there instead of using the named property DefaultValue
on the ConfigurationProperty attribute.

--larsw

Post a reply

Log in to reply.