I am not sure if you need unsafe code in that case (see answer of @mybirthname).
But when unsafe code is needed, it can be enabled in Project properties.
- In the main menu, click
Projectand then<ProjectName> properties... - Click on the
Buildpage. - Select
Allow unsafe code.

Or one can specify /unsafe compiler option explicitly.