Hi,
I have an idea what may cause the InvalidOperationException message.
I'm not sure what you mean by ..."if the default file is used".., but this could cause the error.
You have to create manually(or programmatically) C:\tmp folder and be certain you have checked step '4'.
You have to change your default location of your shared parameter file, i assume.
1. check you have created a folder like "C:\tmp"
2. create a txt document and save it as SharedParams.txt (keep the document blank) in the above directory.
3. in Revit UI go to manage tab select the 'Shared Parameters' icon
4. check the 'Shared parameter file' is referring to 'C:\tmp\SharedParams.txt', if not click 'Browse...' button to set the file
5. then run the external command or macro
6. click again the 'Shared Parameters' icon
7. this is the result if the command have run successfully