Tuesday, August 20, 2013

Fixed: Error CS0030: Cannot convert type DelegateControl to IAttributeAccessor

Sometime, we get the error "error CS0030: Cannot convert type 'Microsoft.SharePoint.WebControls.DelegateControl' to 'System.Web.UI.IAttributeAccessor'" when we customize the masterpage of SharePoint. Many people think that the error comes from mis-typed or SharePoint does not recognize the control with tag name <tag:Delegate> and the solution is to remove that line. Of course, it will work correctly and you could see there is no error after that.

With my solution, there is no need to delete or remove the delegate control out of master page. The error happens because the structure of HTML for delegate control is not correct and you need to review the code to make sure that the hierarchy of HTML page is right. Sometime, there are many break-lines (the empty lines or too much enter key pressed...) also to get this error.

Case Sensitive in SharePoint

I actually didn't know about some areas in SharePoint using declaration with case-sensitive until today I work on List Definition and Custom Activity.

1) When we define a new list, we must define the list of fields and their properties. Especially in the schema for field, take a look the definition schema field by MSDN:

  ID = "Text"  Id = "Text"
  Type = "Data_Type"

ID: is the GUID of the field and put it into {...}
Id: is the text optional

The confusing thing is if you define the field with type is different from Lookup, you might use Id instead of ID. But if you declare the type is Lookup, you must use ID unless the feature couldn't be activated. Althought Id is the optional text but you are still able to use as ID.

2) If you code a custom activity and need it to be availabe on SharePoint Designer while you are designing a workflow, you must define the mapping type in WSS.ACTION file (you can find here C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\Workflow)

The most important thing is all declarations in this file are case-sensitive and you must correct it before to use. It took me some hours to find out the error because I defined ID instead of Id in the field binding

        <FieldBind Field="Error" Text="this message" Id="1" DesignerType="TextBox"/>

That's awesome!