There are many things to take into account when try into gain weight through exercise. Are you doing the right type of exercise?
Are you fuelling your body to perform the workouts needed to build your muscle.
Is your diet giving you enough calories to sustain weight rather than losing it when you are exercising?