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
Hi @jacob.small
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.
@erfajo thank you for your reply . 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.
@RMohareb this is a project open source on github ?
Hi @chuongmep
Not yet,
I publish only the dynamo package.
Your package is build support for Dynamo Revit or Dynamo civil ?
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.
Hi @chuongmep @erfajo thank you for help (you always support me )
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
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 @jacob.small 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.
@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.
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.
it work fine by using use late binding
thank you @zachri.jensen you are amazing
Now i need to update my package to use late binding instead of early binding. I have alot of work .
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 @jacob.small @solamour @Paolo_Emilio_Serra1 @Anton_Huizinga @ingenieroahmad
You can add yourself to that list as well
@RMohareb Can you point me to the version of the package “BriMohareb_23” that can reproduce the issue ?
I tried it with the latest version (5.0.2) but the issue does not seem to reproduce when DynamoLoads it and Civilconnection.
Hi @tiberiu.pinzariu
BriMohareb_23 v 5.0.2 can load with Civilconnection.
can you send me the error?
or it can not load together?
@RMohareb I am trying to reproduce the issue (“I can not use Civilconnection package and BriMohareb_23 at the same time”)
Indeed BriMohareb_23 v 5.0.2 seems to work fine.
Can you share a version of the package that can reproduce the issue show here?
Try “version”:“3.2.1”