ENUM underlying type and object must be same type in class AudioSubTypes


After making a change (and I don't remember !!!!! what I changed, but I think I was only changing from Net 3.5 to Net 4.5). I get an error "ENUM underlying type and object must be same type , type passed was System.UInt16, the enum underlying type was System.Int16" in
 public static AudioEncoding EncodingFromMediaType(Guid mediaType)
            var bytes = mediaType.ToByteArray();
            int value = BitConverter.ToInt32(bytes, 0);
            if (Enum.IsDefined(typeof(AudioEncoding), (ushort)value)) 
                return (AudioEncoding)value;

            throw new ArgumentException("Invalid mediaType.");
Looking in the source,"he" was right as AudioEncoding is defined as short.
I changed ushort in short and now it works, but is this the real solution? or is there an underlying problem, that I did not see? after all it was a working program, that all of a sudden did not work anymore!
Closed Apr 19, 2015 at 7:49 PM by filoe