If you can do a marathon, you can manage a 40 mile ultra no problem. The trick is to change your mindset, run nice and slow, walk long uphills, and eat constantly.
As for the timing, I think it could actually be good to do between the half and full as more base training for the full marathon. Then you’ll know you’ve got the base fitness and can work on speed and honing in on the marathon.
This is the approach I did this year- I did a 60 mile ultra in August and spent most of June and July logging long slow mileage. Now I am prepping for a marathon in November and am less concerned about running high mileage and focusing a bit more on speed. Trying to significantly PR in the marathon so this is quite helpful. And anytime that thought of “26.2 miles is a looong way to go” comes into my head, I can pretty easily squash it by saying “I did 60 miles earlier this year, yeah I can handle 26”