May be a simple question..
I have an interface:
public interface ISanitizer
{
T Sanitize(T data_);
}
And an implementi
In my particular case the following code generated the same error:
return (T) someData;
What helped me out - double cast with object:
E.g:
static T MyFunction() {
string s = "test";
if (typeof(T) == typeof(byte[]))
return (T)(object)System.Text.Encoding.ASCII.GetBytes(s);
else if (typeof(T) == typeof(string))
return (T)(object)s;
else throw new Exception();
}
...
var ba = MyFunction();
var bs = MyFunction();