Midi export is a mess

I exported a score as midifile, but the result is a mess. There are lot of long notes, which are in the midi file but not in the score. What is going wrong here?
Charpentier_-_Trio Flöte, Geige, Klarinette, Klavier.dorico (1.5 MB)
Charpentier_-_Trio Flöte, Geige, Klarinette, Klavier - Partitur - Trio de Monsieur Charpentier.mid (12.3 KB)

When you import the MIDI file into Dorico, in the MIDI Import Options window which opens, check the box (bottom LH corner) for Filter out key switches outside range:

The problem is not the import, but the export as midifile.

You will probably have to apply what I suggested in the importing application (Sibelius, MuseScore, Finale, etc.) if it offers that feature when importing MIDI.
Because these low notes, which apparently are caused by MIDI keyswitches, seem to affect only strings (I might be wrong there), you could try changing the instruments to something else before exporting MIDI from Dorico.

Also (and a much better answer), see the solution given by Daniel Spreadbury which is no. 5 in this thread:

Those notes are all key switches, so they’re certainly not vestigial. When you export MIDI from Dorico, it exports exactly the same music that it plays back. If key switches are used during playback, then key switches will appear in the exported MIDI.

If you want to ensure that your exported MIDI data contains only notes, the best thing to do is apply the HSSE (SE) playback template before you export your file, as this playback template uses only simple GM-style sounds that don’t cause any key switches or MIDI CC values to be played back. If you’ve tweaked the playback of your project, I suggest you change the playback template on a copy of the project rather than on your original, as changing playback template is not undoable.

Thanks for your advice, I will try it. But IMO the behaviour of Dorico is strange, because I haven’t used any keyswitches in the score. Why puts Dorico these switches into the score ? And why isn’t there an option to export Midi without expressions and keyswitches ? Changing the playback template each time, when I export as midi, isn’t very funny.

If your Expression map uses a keyswitch for “Natural”, then it will play that note.

You could change the Expression map to Default, instead.

What are you exporting MIDI for? Most people want to use the same sample instruments in another app, so they want the same MIDI data.

I need a midifile for the playback of the piece on a keyboard, which has an inbuild midiplayer. So obviously the midi file must be clean.

Is the keyboard connected to your computer via MIDI? You can send the MIDI data directly from Dorico to a MIDI Instrument, assign its own Expression Map.
Screenshot

@StevenJones01 gave you the way to achieve this: " apply the HSSE (SE) playback template before you export your file,"