Where is the 'indeterminate type'?

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-05-04T15:00:38Z Indexed on 2010/05/04 15:28 UTC
Read the original article Hit count: 137

Filed under:

I'm defining the following type extension:

type System.Reflection.MemberInfo with
    member x.GetAttribute<'T when 'T :> Attribute>(required, inherit') =
        match required, Attribute.GetCustomAttribute(x, typeof<'T>, inherit') with
        | true, null -> invalidOp (sprintf "Missing required attribute: %s" typeof<'T>.FullName)
        | _, attr -> attr :> 'T

The last match expression (attr :> 'T) gives the error:

The static coercion from Attribute to 'T involves an indeterminate type based on information prior to this program point. Static coercions are not allowed on some types. Further type annotations are needed.

I've tried annotating the function return type, but got the same result. I would hate to change this to a dynamic cast. Is there a way to make the static cast work?

© Stack Overflow or respective owner

Related posts about F#