Show/Hide Toolbars

XSharp

Cannot implicitly convert type 'type1' to 'type2'. An explicit conversion exists (are you missing a cast?)

 

This error occurs when your code tries to convert between two types that cannot be implicitly converted, but where an explicit conversion is available. For more information, see Casting and Type Conversions.

 

The following code shows an examples that generates XS0266 and how to avoid the error

 

 

 
FUNCTION Start()
LOCAL r8 := 1.234 as REAL8
LOCAL i AS INT
i := R8         // this will produce error XS0266
i := (INT) r8   // this prevents the error because there is an explicit cast
 
 

You can suppress this error for numeric conversions with the compiler option /vo11 (for assignments from larger types to smaller types or for assignments from fractional types to integral types).
For assignments between signed and unsigned numbers the error can be suppressed with /vo4