Ramayana is the clean one in which Lord Rama fought with Ravana face to face and at last Dharma won. Killing of vali is not acceptable in that. But in Mahabaratha there are many connivances like hiding the sun thru chakra, getting the kavacha kundala from karna [karna is mightier than arjuna] etc.Dharma only won at last. From that time onwards kali entered this earth [after Krishna went to his place]. What teaching we should learn from the connivances of Mahabaratha? Krishna is not in Ramayana. I have given both the qualities of Rama and Krishna and wanted a comparison thought.
Well, it is all about Dharma at the end of the day. Dharma was/is considered to be the backbone of human society. If some Adharma has to be committed to preserve Dharma in the society, either god in his avatar form or his deva or human subordinates would have to do it.
Let me put this into perspective for you. Just imagine that in Mahabharata there were no Maharathis and Athimaharathis (Great warriors) such as Karna, Guru Drona, and Bishma. Duryodhana and Shakuni would not even have had the courage to invite the Pandavas to the gambling arena which eventually led both sides into war. To so called "nullify" and make both sides almost equally powerful, Lord Krishna had to use Adharmic methods.
No one can deny that both sides of the battlefield committed Adharma. If blocking the sun was Adharma, so is the killing of Abhimanyu by Karna, Guru Drona, Bishma and other warriors simultaneously. The main reason Abhimanyu was killed is Jayathradha. He closed the Chakra Vyuha and prevented the Pandavas from entering and all of warriors simultaneously attacked Abhimanyu after they learned that he could not be defeated individually by any one of them.
Adharma is done to uphold Dharma all the time. In school and at home teachers and parents sometimes slap their kids in order to instill some values in them. If a child is being disrespectful to the elderly, then you have to scold or even hit the child to make the child abide to Dharmic values. Slapping, hitting and scolding may sound like Adharma but it is done to correct and uphold Dharma in the society.
What leads you and others towards god is Dharma and prevents you from realizing god is Adharma.