Assure that \layout is the first element of the lyx file.