The error might be related to this function call, but I didn't see it in your code snippet, it requires Network connection to the central file with my experience.
WorksharingUtils.GetUserWorksetInfo(revitCentralFile)
If you want to preserve worksets, you can set WorksetConfiguration to OpenLastViewed, it's the default option of the Revit OpenFileDialog with my finding.
Here is my test code. It works as expected and the result is the same as the Revit OpenFileDialog does.
public void CreateSaveDetachedFile2(UIApplication application, string revitFilePath) { //Get information of current opened revit file FileInfo filePath = new FileInfo(revitFilePath); ModelPath revitCentralFile = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath.FullName); var openConfig = new WorksetConfiguration(WorksetConfigurationOption.OpenLastViewed); OpenOptions openOptions = new OpenOptions(); openOptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets; openOptions.Audit = false; openOptions.AllowOpeningLocalByWrongUser = true; openOptions.SetOpenWorksetsConfiguration(openConfig); application.OpenAndActivateDocument(revitCentralFile, openOptions, false); }
Hope it helps.