Sunday, October 28, 2012

Validation is a boxing value is default

I very like my lovely extension IsDefault but unpossible to use it where a value is boxing. A cool feature of C#  default(...)  cannot help because a argument required Type. After long research was created small solution:

static bool IsDefault(object o)
{
    if (o == null)
    {
        return true;
    }
    //Check is type os object is ValueType
    if (o.GetType().IsValueType)
    {
        return Activator.CreateInstance(o.GetType()).Equals(o);
    }
    //ReferenceType
    return false;
}


Also can be implemented as extension.

Thursday, October 18, 2012

An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'XXX' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.

A web.config of project include next rows:
...
<extensions>
    <behaviorExtensions>
        <add name="ELEMENT" type="YYY.ZZZ,YYY.XXX, Version=1.0.0.0,Culture=neutral, PublicKeyToken=null" />
    </behaviorExtensions>
</extensions>
...
<behavior name="BehaviorName">
          ELEMENT />
</behavior>

In the start project WCF is throwing exception and message:
"An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'ELEMENT' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions."

A problem exists in file AssemblyInfo of YYY.XXX and not in config.
YYY.XXX change build number in every compilation but WCF is require a full name of assembly (AssemblyQualifiedName) and exact assembly file version number.

Open AssemblyInfo and see last 2 rows:
[assembly: AssemblyVersion(...)]
[assembly: AssemblyFileVersion(...)]

If a code looks like this:
[assembly: AssemblyVersion(5.0.1.0)]
[assembly: AssemblyFileVersion(5.0.1.0)]

You not reading current article but if acode looks like this:

[assembly: AssemblyVersion(5.0.1.0)]
[assembly: AssemblyFileVersion(5.0.1.*)]

This is a time to change it and resolve a problem. Enjoy.