Fail to Load two packages access to the same API

Dynamo can not load two packages access to the same API.for Example I can not use Civilconnection package and BriMohareb_23 at the same time. I need to remove one of them and use only one becuse both access to civil 3d api. Is any way to load both togethe?.
here the error if i try to load BriMohareb_23 when i already load civilconnection
image

1 Like

Hi @JacobSmall

in your comment you refer to use “alias” to able to load to pakedge use the same DLL.
Do you mean i use “alias” when i load Civil3d Dll into my code? (as show below) . I try that but i can not load my pakedge with civilconnection pakedge after I befiend All alias of civil3d DLL to new defination insted use “global” (i use “Mohareb” insted “global”). please advise.

image
image
image

Don’t include others assembly in your solution. Do instead include an “about” node that your functions need a specific software to be installed. However, if it is a third party assembly that isn’t common then you can/should consider to include the assembly.
An AutoCAD assembly is not among assemblies to include!

In my package example do i NOT include ifcexporter assemblies, users need to install that and maintain it. However, from time to time do a user ask why the ifcexporter nodes are missing… And the answer is always due to missing installation or missing maintenance.

Furthermore if you need two different versions of an reference assembly, then is it a completely other ballgame. I would suggest you to see stackoverflow for that. My package is coded for usage with the last four versions of Revit and their coherent Dynamo version… This is a job to handle and maintain… That is certainly not an easy task!

2 Likes

@erfajo thank you for your reply :pray:. Here i do not like to add others assemble in my solution. My problem, my package work fine in Dynamo, but it cannot load if other package loaded into dynamo and use the same reference that i use in my package. For example: my package access civil3d api for that i use civil3d Dll in my code as a reference also Civilconnection package use the same reference. i can not use both at the same time i should load only one in dynamo. I need to find a way to use them in Dynamo.

…and you dont include it when compiling?

try to see how i DONT include the ifc exporter

2 Likes

Yes i do not include it when compiling

@RMohareb this is a project open source on github ?

Hi @chuongmep
Not yet, :pensive:
I publish only the dynamo package.

Your package is build support for Dynamo Revit or Dynamo civil ?
image

Dynamo revit. It access to com api for Civil3D. This error aber if you load Civilconnection package at the same time. If you upload Civilconnection package it will be work

With Com API, it is hard to have a solution correct, I hope you will try open source and every one can look and help. Sorry, I don’t have a proper solution to this problem either.

1 Like

try to see that you have Embed Interop Types = true, try to set that also to false

1 Like

Hi @chuongmep @erfajo thank you for help (you always support me :pray:)

sure i will add the source into github.
for now here is part of my code have the problem. I hope it can help to solve the problem.
https://drive.google.com/drive/folders/14iZEiGUAhGz9A5B734-qAXOkVN90OGFp?usp=sharing



using System;
using Autodesk.AutoCAD.Interop;

using  Autodesk.AECC.Interop.UiRoadway;


using System.Collections.Generic;



namespace Civil3D
{

    public class Civil3DApplication
    {

        string m_sAcadProdID = "AutoCAD.Application";


        string m_sAeccAppProgId = "AeccXUiRoadway.AeccRoadwayApplication.13.5";
        public AcadApplication m_oAcadApp = null;
        public AeccRoadwayApplication m_oAeccApp = null;
        private AeccRoadwayApplication _civApp;


        /// Constructor
        public Civil3DApplication()
        {
            this._civApp = this.GetApplication();
        }


        internal AeccRoadwayApplication GetApplication()
        {

            //Start Civil 3D
            try

            {
                m_oAcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(m_sAcadProdID);
            }
            catch (Exception /*ex*/)
            {
                System.Type AcadProg = System.Type.GetTypeFromProgID(m_sAcadProdID);
                m_oAcadApp = (AcadApplication)System.Activator.CreateInstance(AcadProg, true);
            }


            //Construct AeccApplication object, Document and Database objects
            if (m_oAcadApp != null)
            {
                m_oAeccApp = (AeccRoadwayApplication)m_oAcadApp.GetInterfaceObject(m_sAeccAppProgId);


            }


                return m_oAeccApp;
           

          

        }





        public override string ToString()
        {
            return string.Format($"Civil3DApplication (ActiveDocument = {this._civApp.ActiveDocument.Name})");
        }






    }
}


@erfajo
the same problm

image

image

Just to be clear, I load four different versions og both Revit and Dynamo API that are interconnected since the specific dynamo version is bound to a specific Revit version. Is that also the case for you? if so you need to take care of this in your setup when coding.

This gives 8 projects that has a specific set of references for Revit, and the same goes for the IFCnodes due to the ifc exporter. All in all do I maintain 28 projects in my Visual Studio setup to control the different versions and combinations…
image

1 Like

In my case i do not need to load different Version. In my project i have only one Version 2023 for revit, civil3d and Dynamo.
The conflict come when i load my packedge into dynamo,
I have two case:
1- My Dll load in dynamo and there are “NO” othe packedge (created by other) load into dynamo use the same refrance i used it in my packedge ------> my packedge work good and can load into dynamo
1- My Dll load in dynamo and there are othe packedge (created by other for example “Civilconection” packedge ) load into dynamo use the same refrance i used it in my packedge ------> my packedge “NOT” work and can NOT load into dynamo.

As i understand in your case i need it if i need to create package cover more than version.
In your case you use different version of the refrance into your C# project.
In my case i use refrance and other Packedge(created by other) use the same refrance. Dynamo can NOT Load these two packedge at the same time i should load one of them.

You can test :
load my Package “BriMohareb_23” with out “civilconnection” package it will be loaded into dynamo.
In the otherhand if you try to load my Package “BriMohareb_23” and you have already “civilconnection” package it will be NOT loaded into dynamo.

Here @JacobSmall refer to the “alias” to over come this problem. I try it by add Alias to all ref. i use in my project but it dose not work.

…does the other package “Civilconection” have the assemblies included? if so… then no matter how you do it. It will fail always! however, you can try to remove those conflicting assemblies from the “Civilconection” package and see if it works anyway.

I have seen cases like this when newbie codes start, and they release packages including dynamo and revit assemblies… and then upload them i the package manager… when ohers then include such a package, then is all other packages in trouble.

1 Like

FYI @Paolo_Emilio_Serra1

@RMohareb I think the only solution to your problem is to use late binding instead of early binding of the COM types in your code. The CivilConnection VS project has “Embed Interop Types” set to True, so I don’t think there is a quick fix since the package is already deployed publicly. So basically what you’d need to do is remove all references to COM interop assemblies in your project and use dynamic types instead of the strongly-typed COM interfaces. It’s a pain for development since you can’t take advantage of IntelliSense, but if you minimize interaction with the COM API as much as possible, then it probably isn’t too big of a headache. Using the example code you posted above:

using System;

namespace Civil3D
{

    public class Civil3DApplication
    {
        string m_sAcadProdID = "AutoCAD.Application";
        string m_sAeccAppProgId = "AeccXUiRoadway.AeccRoadwayApplication.13.5";
        public dynamic m_oAcadApp = null;
        public dynamic m_oAeccApp = null;
        private dynamic _civApp;


        /// Constructor
        public Civil3DApplication()
        {
            this._civApp = this.GetApplication();
        }

        internal dynamic GetApplication()
        {
            //Start Civil 3D
            try

            {
                m_oAcadApp = System.Runtime.InteropServices.Marshal.GetActiveObject(m_sAcadProdID);
            }
            catch (Exception /*ex*/)
            {
                System.Type AcadProg = System.Type.GetTypeFromProgID(m_sAcadProdID);
                m_oAcadApp = System.Activator.CreateInstance(AcadProg, true);
            }


            //Construct AeccApplication object, Document and Database objects
            if (m_oAcadApp != null)
            {
                m_oAeccApp = m_oAcadApp.GetInterfaceObject(m_sAeccAppProgId);
            }
            return m_oAeccApp;
        }

        public override string ToString()
        {
            return string.Format($"Civil3DApplication (ActiveDocument = {this._civApp.ActiveDocument.Name})");
        }
    }
}

I think it’s probably safe to say that it should be a best practice for us developers to use late binding when working with COM interop and Dynamo. That way it’s easier for the next developer in line and we don’t have a “first package loaded wins the race” scenario.

4 Likes

I thought we had addressed this issue already in 2.12/2.13 timeframe, but I guess not, will reopen our task to investigate solutions.

6 Likes

Hi @mzjensen

it work fine by using use late binding
thank you @mzjensen you are amazing :v:
Now i need to update my package to use late binding instead of early binding. I have alot of work :face_with_peeking_eye: .

It work by using

Really this forum is amazing. I feel I have a strong team work. Every time i have an idea or problem i get a support. this forum is very important for all my career journey.
Thanks you for your support @erfajo @chuongmep @Michael_Kirschner2 @JacobSmall @solamour @Paolo_Emilio_Serra1 @Anton_Huizinga @ingenieroahmad

5 Likes