zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    template
    open File Browser in shell
    自定义模板类型vs模板类型自动推测
    protobuffer
    多重继承&虚继承
    What I'm Researching
    JobTracker和TaskTracker
    MapReduce
    How To Use Google Flags
    Frequently Used Shell Commands
  • 原文地址:https://www.cnblogs.com/junqilian/p/2724880.html
Copyright © 2011-2022 走看看