SynchronizeWithCentral Errors

SynchronizeWithCentral Errors

smadera_AEQHT48JJ3NM
Explorer Explorer
729 Views
3 Replies
Message 1 of 4

SynchronizeWithCentral Errors

smadera_AEQHT48JJ3NM
Explorer
Explorer

Hi there, I'm working on a script to automatically link files hosted on BIM360 and then synchronize back to central to save the changes. Everything works perfectly except when it gets to the synchronization. For a little more context, the code works by manually opening a workshared, cloud-hosted file from BIM360 in Revit, and then the action is triggered manually (I've been using the Add-In Manager). It gets any necessary cloud data from the open document. Authentication for BIM360 is handled manually, but with the token it works (it uses this to find the linked files, and this works fine).

 

The issue is I cannot get the file to synchronize at all. I've tried SynchronizeWithCentral using the method just copied from the API documentation:

 

public void SyncWithoutRelinquishing(Document doc)
{
    // Set options for accessing central model
    TransactWithCentralOptions transOpts = new TransactWithCentralOptions();
    SynchLockCallback transCallBack = new SynchLockCallback();
    // Override default behavior of waiting to try again if the central model is locked
    transOpts.SetLockCallback(transCallBack);

    // Set options for synchronizing with central
    SynchronizeWithCentralOptions syncOpts = new SynchronizeWithCentralOptions();
    // Sync without relinquishing any checked out elements or worksets
    RelinquishOptions relinquishOpts = new RelinquishOptions(false);
    syncOpts.SetRelinquishOptions(relinquishOpts);
    // Do not automatically save local model after sync
    syncOpts.SaveLocalAfter = false;
    syncOpts.Comment = "Changes to Workset1";

    try
    {
        doc.SynchronizeWithCentral(transOpts, syncOpts);
    }
    catch (Exception e)
    {
        TaskDialog.Show("Synchronize Failed", e.Message);
    }
}

// This class implements the ICentralLockedCallback to override Revit's default
// behavior for how to handle when the central model is locked by another user
class SynchLockCallback : ICentralLockedCallback
{
    // If unable to lock central, give up rather than waiting
    public bool ShouldWaitForLockAvailability()
    {
        return false;
    }

}

 

This produced an Autodesk.Revit.Exceptions InvalidOperationException: Saving local before first reload latest and after saving changes to central in Synchronize with Central is mandatory for server-based local models. Then here is where it gets even more confusing: I changed line 15 to

syncOpts.SaveLocalAfter = true;

 to fix this problem. And then I get the error: An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Length cannot be less than zero.

 

Any further changes to the code produced this error. I removed the relinquish options, as my original intent was to relinquish everything (I was just testing the given code), same error. I tried keeping everything with the default settings:

 

TransactWithCentralOptions transact = new TransactWithCentralOptions();
            SynchronizeWithCentralOptions synch = new SynchronizeWithCentralOptions();
            synch.Comment = "Synchronized with central";
            doc.SynchronizeWithCentral(transact, synch);

 

Same error, length cannot be less than zero. I tried using someone else's code I found online, which they claimed works. Same error. Is there any way to synchronize this file? It works manually, of course, but I'd like to automate it as it's part of a larger script.

 

I've also tried using SaveAs with the cloud path, Save (which can save the local version), SaveAsCloudModel and SaveCloudModel, none of which work. Any help would be so appreciated 🙂 

 

Lastly, here's the stack trace of the error:

 

Parameter name: length
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
   at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at Autodesk.Revit.UI.Collaborate.Views.CollaborationSWCDialog..ctor(SWCStep step, IntPtr pOwner)
   at Autodesk.Revit.UI.Collaborate.Views.CollaborationSWCDialog.WindowWorkerThread(Object arg)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)</ExceptionString></Exception></TraceRecord>
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Length cannot be less than zero.

The program '[12456] Revit.exe' has exited with code 4294967295 (0xffffffff).

 

730 Views
3 Replies
Replies (3)
Message 2 of 4

mhannonQ65N2
Collaborator
Collaborator

It looks like this is an error with loading assemblies. Is your addin/macro (or any other installed addin/macro) using any custom assembly resolution via the AppDomain.AssemblyResolve event?

 

Also, can you include the stacktrace(s) of any inner exceptions? The method at the top of the provided stacktrace does not have a parameter named 'length'.

0 Likes
Message 3 of 4

smadera_AEQHT48JJ3NM
Explorer
Explorer

Hi there,

 

Sorry for the delay in response, tried troubleshooting more to get somewhere but still nothing.

 

To answer your questions: no, there's no custom assembly resolution. There are also no inner exceptions, just goes straight to length (even with a try-catch, it just jumps to mscorlib.dll).

 

There was one peculiar thing I noticed while using the debugger in Visual Studio - I put a breakpoint right before the Synchronize function to see what variables were getting input to see if I could locate the problem there. Everything seemed okay (SynchonizeWithCentral and TransactWithCentralOptions showed expected results when I hovered over them), but whenever I tried to hover over the document doc (Document doc = uidoc.Document), it would crash Revit and quit debugging. This happened every time, even with different files open. Not really sure what that could mean.

0 Likes
Message 4 of 4

mhannonQ65N2
Collaborator
Collaborator

It looks like the exception happens when Revit tries to open the CollaborationSWCDialog. What happens when you try to manually synchronize with central? Also, are there any other addins (including 3rd party ones) running?

 

Also, the exception seems to be related to localization, so maybe you could try running Revit in a different language. That won't be an effective solution but what happens could shed more light on the problem.

 

As for Visual Studio crashing when hovering over the document object, I'm not too sure. When I hover over a document object in Visual Studio, I always see an exception in one of its properties that has something to do with printing. This doesn't cause a crash or anything for me. Maybe try changing Visual Studio's exception settings and/or updating Visual Studio?

0 Likes