SharePoint 2010: Error Mapping to Picture Hyperlink with SPMetal

753 Views Asked by At

Whenever I have a column of type hyperlink with the format set for pictures, I get an error whenever there is actually a value in that column. The exception it throws is "Specified cast is not valid".

My thought is that the problem is either here (the FieldType being set to Url):

[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "FOO", Storage = "FOO_", FieldType = "Url")]
public string FOO
{
    get
    {
        return this._FOO;
    }
    set
    {
        if ((value != this._FOO))
        {
            this.OnPropertyChanging("FOO", this._FOO);
            this._FOO = value;
            this.OnPropertyChanged("FOO");
        }
    }
}

Or here (it being cast to a string):

private string _FOO;

But I'd have no idea what the proper values for either of those fields should be. Any help would be greatly appreciated.

It works whenever this field does not have data in it and I JUST used SPMetal to generate the class, so I'll get the two most obvious questions out of the way.

1

There are 1 best solutions below

0
On BEST ANSWER

Link to the answer: https://mgreasly.wordpress.com/2012/06/25/spmetal-and-workflow-associations/

Turns out it is a known bug when mapping lists that have associated workflows. SPMetal assigns it as a nullable integer when it's supposed to be an Object, hence the cast error.

Workaround: manually edit the mappings to make the type it returns an object or ignore the column by using a parameter map.