I understand your problem, but as JRE points out in the comments, a bit more structure and explanation to your points would have gone a long way.
There is no guarantees in simple circuits.
A relay running off of the grid to connect grid and inverter to the house & generator, as was my first though, would just keep running off the inverter if the grid dies, accomplishing nothing.
Similar solutions have similar problems.
One thing I assume is that your diesel generator has an internal system, being powered from its own battery & recharge system?
There must be some opportunity there to hook up a relay that throws the inverter off the system if your diesel is running.
The normal relay won't be super cheap either, considering you have a reasonable amount of peak power in the house or building using this set-up and you'd need to dimension for worst case, but it wouldn't be particularly expensive and such things can be found second hand. Since the generator runs off a 12V or 24V battery most likely and those coil voltages are very common in relays.
Generator on -> Relay on -> Inverter off.
Although, you might want an even cooler system in the long run, where the solar power keeps doing something useful. Anything it does will save you diesel power and since you already paid for the solar panels and will have to keep buying the diesel every time it's used up.