I would recommend focusing your food intake around foods high in calories from fat and protein. If you can't eat a lot of food without feeling the pain change the types of food you are eating. Steaks, bacon, all cooked with EVOO or butter. Don't neglect your vegetables but perhaps look for higher calorie veggies. Have you tried drinking some of your calories? Perhaps an all natural protein shake?
Definitely stay away from pastas, breads, and processed foods as that is not the healthy way to gain weight.
Also, no cardio, focus on weight training. By eating plenty of fats and proteins, and healthy carbs, you're priming your body to create more muscles..so lift away. With a hernia I might see a professional to get some guidance on weight amounts, restricted moves, etc.
Also eat more frequently. Smaller meals at regular intervals. This way you are getting in those extra calories without the bulk all at once. An avocado here, some bacon there, a hard boiled egg, some nuts.
Have you been tested for worms? An infestation can result in low weight.
Have you tried weight training with some added protein? That way you'll gain muscle, not fat, but don't overdo the protein as some do.