It was not the first time I stumbled upon “Extension element 'X' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/Y.”
But as always, the knowledge last used longer than a year ago just goes away.
I know I should put a fully qualified name into the extension type even if mine is not strong named. Quite stupid from my opinion to do so anyway, but I learnt my lesson for this 3 years ago, so what the heck it is now?
If we look with reflector through the top of a stack trace:
internal bool CanAdd(string extensionCollectionName, ContextInformation evaluationContext)
{
...
We will see where the problem is hidden:
string assemblyQualifiedName = this.ThisType.AssemblyQualifiedName;
foreach (ExtensionElement element in elements)
{
string str2 = element.Type;
if (str2.Equals(assemblyQualifiedName, StringComparison.Ordinal))
{
flag = true;
break;
}
if (assemblyQualifiedName.StartsWith(str2, StringComparison.Ordinal))
{
Type type = Type.GetType(str2, false);
if ((type != null) && type.Equals(this.ThisType))
{
flag = true;
break;
}
}
So if I put by chance an extra whitespace or forgot to use one where required, I’ll be punished with the error above and … And I don’t exactly agree with engineer that made such a design decision I should say.
If we count the time such an engineer is incorporating into his design decision, time “wasted” by his fellow dev users, my message to the guy would be - Provide a better error message or risk joining the collection of stupid and useless error messages here:
As I guess discussion about significance of whitespaces here could be very long!
1 comment:
Make sure you have right assembly version
if you put Version=1.0.0.000 it will bark this exception.
if you put Version=1.0.0.0 it may just work.
Parser is not lenient as it should be.
Post a Comment