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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值