Same as in my other question, the solution had nothing to do with the errors that I posted above. The problem was actually the certificate for tmx signing, ordered from beckhoff. In the windows environment variables, there was an old certificate that no longer worked. Even though I put the new certificate in the TC build setting in Simulink, the certificate from the environment variables caused the code generation to crash.
So to solve this, add the latest activated certificate to the windows environment variables and restart Matlab.