Hi,
The reason the error is cropping up is because, while the Output Port Dimensions have been explicitly specified, the S-function is relying on implicit inheritance to determine the dimensions of the Input Port. Due to the differing sizes, there's a conflict. By specifying the InputPort dimensions in this way in the setup method:
block.InputPort(1).Dimensions = 4;
you would be explicitly specifying the Input Port dimensions and the S-function should run fine.