Reputation: 1409
Compiling a VS 2010 c# project (.NET 4.0, any CPU, allow unsafe code = checked) we are getting a variety of compile errors as below:
Operator '*' cannot be applied to operands of type 'System.IntPtr' and 'int'
Constant value '325486741' cannot be converted to a 'int' (use 'unchecked' syntax to override)
Cannot convert type 'string' to 'char*'
Cannot implicitly convert type 'long' to 'byte*'. An explicit conversion exists (are you missing a cast?)
Invalid expression term 'ref'
All these are occurring in 'unsafe' methods.
How to resolve these ?
Upvotes: 0
Views: 2468
Reputation: 210755
We'd need to see your code, but I'd say that the "unsafe" part is irrelevant to the errors, since those seem to be problems with casting and such.
Here's some info that might help:
Try casting to an int or long first.
Try using unchecked((int)variable).
Try using:
fixed (char* pChar = my_string) { ... }
Try casting: byte* pB = (byte*)value;
I can't say much about this one without the code.
Upvotes: 2