I just answered your corresponding thread in the Revit API discussion forum:
https://forums.autodesk.com/t5/revit-api-forum/how-to-load-revit-file-in-api-using-c/m-p/7071015
Calling directly into the Revit API from an external context is, was and always has been illegal.
The Revit API cannot ever be used except within a valid Revit API context.
Such a context is provided exclusively by Revit call-back methods.
You need to subscribe to a Revit event, such as an external command Execute method.
Within the event handler, the Revit API can be used.
You can also use the Revit API to set up an external event that can be raised from a non-Revit-API context, such as your standalone external application.
This is demonstrated by the ModelessDialog/ModelessForm_ExternalEvent Revit SDK sample. Here is all you need to know about the Revit SDK and getting started with the Revit API.
This question has been answered and discussed in depth numerous times in the past, both in the Revit API discussion forum and by The Building Coder.
Many examples and further explanations are provided in The Building Code topic group on Idling and External Events for Modeless Access and Driving Revit from Outside.
Here are some of the Revit API forum discussion threads addressing similar issues: