Failed to add FS to collection at ResourceService.SetResource in Map 3D 2013

By Daniel Du

If you are migrating your application to Map 3D 2013 and run into this problem, this post may be helpful for you. Let’s say you have a custom command to add resource with Resource Service,for example, you are connecting to a feature source, like the implementation in the “BuildMap” sample of SDK. If you happen to run your custom command in session context:

<CommandMethod("MyCommand", CommandFlags.Session> _
or

[CommandMethod("MyCommand", CommandFlags.Session)]

or trying to add FDO connection from a pallet set.

You may get the error message at ResourceService.SetResource():

“Failed to add FS to collection“

The solution is to add DocumentLock before setting resource. Here is a pseudo code snippet:

    [CommandMethod("MyCommand", CommandFlags.Session)]

    public void MyCommand() // This method can have any name

    {

      Document doc = Application.DocumentManager.MdiActiveDocument;

 

      // You must lock the document in Map 3D 2013

      using (DocumentLock docLock = doc.LockDocument())

      {

        // ...

 

        ResourceService.SetResource(...);

        //...

      }

 

    }

And here is the explanation:

In Map 3D 2012, the Resource Manager was not an AcDbObject – so you did not need to have a DB Lock to access it.  Thus, it was OK to run the custom command in Session context.

In Map 3D 2013, the Resource Manager is moved into the Database, so you are now required to have a Document Lock to access it.  Therefore, the custom command can no longer be run in Session context.

Hope this helps.


Related Posts Plugin for WordPress, Blogger...