It's exploding probably because "SHA256" is not proper Oid descriptor.
It should be:
signer.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1");
An "Internal server error" means that you haven't properly setup the objects and/or properties required to use the Signer. There's probably more that's wrong but you're not showing enough code to make that determination.