map2015 - problem to load .net-file

map2015 - problem to load .net-file

jan_tappenbeck
Collaborator Collaborator
967 Views
10 Replies
Message 1 of 11

map2015 - problem to load .net-file

jan_tappenbeck
Collaborator
Collaborator

Hi!

 

i have several dll-files and one of these i want to autoload by reg-key like

 

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R20.0\ACAD-E002\Applications\EBL_AcadLoader]
"LOADCTRLS"=dword:00000002
"MANAGED"=dword:00000001
"DESCRIPTION"="EBL_AcadLoader"
"LOADER"="C:\\Program Files\\Autodesk\\AutoCAD 2015\\Map\\bin\\EBL_AcadLoader.dll"

on several machines this works fine (win7).

 

 

now i want to transfer to other machines (win7 and win10).

 

the function of the loaded dll will not show (autocomplete) in command line.

 

so i try to load by "netload" - there no error-message will show. but no error-message will show! possible command not show in commandline!!

 

did some had an i idea to find the reason? is there a logfile of netload ??

 

regards Jan

0 Likes
968 Views
10 Replies
Replies (10)
Message 2 of 11

norman.yuan
Mentor
Mentor

@jan_tappenbeck wrote:

Hi!

... ... 

so i try to load by "netload" - there no error-message will show. but no error-message will show! possible command not show in commandline!!

 

... ...

regards Jan


I am not very sure what you mean here, but guess that you mean the you loaded the DLL with with command "NETLOAD". 

 

AFTER the command "NETLOAD", what would happen would depend on what the DLL does. If it has implemented IExtenstionApplication, some code in the Initialize() would run immediately upon loading, which may result in exception, depending on the code in it. If exception does happen in Initialize() and it is not caught, AutoCAD would silently go ahead, but the code in the DLL would be not executable. That is, any CommandClasses/Methods defined in this DLL would be not useable.

 

So, in your case, if if the same DLL works OK when "NETLOADed" into some computers, but not in other computers, you would first examine code in IExtenstionApplication.Initialize() to see if there is some possibility of runtime exception not being handled, which could be caused by the differences of Windows configurations. Rule of thumb: ALWAYS use try...catch... block to wrap code in IExtensionApplication.Initialize().

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 11

jan_tappenbeck
Collaborator
Collaborator

dear norman,

this mid be the right way - by "IExtensionApplication".

my source, which works on other computers looks like

Public Class main
    Implements IExtensionApplication

    Public Shared IsAcLoaderInit As Boolean = False
    Dim docMgr As DocumentCollection = Application.DocumentManager
    Private _Editor As Autodesk.AutoCAD.EditorInput.Editor
    Private _acDoc As Autodesk.AutoCAD.ApplicationServices.Document
    Private _LogMode As Boolean = True
    Private _SrvMisc As New EBL.Service.Miscellaneous
    Private _SrvLogin As New EBL.Service.LoginAD
    Private _TryReport As New EBL.Logger.TryCatchReport
    Private _Loader As New EBL_AcadLoader.Loader

    Private _TableName_Organisation As String = "X:\AcadKonfiguration\Organisation.db"
    Private _connDBOrga As SQLiteConnection = Nothing

    ''' <summary>
    ''' Initalisierung der Funktion
    ''' </summary>
    Public Sub Initialize() Implements IExtensionApplication.Initialize
        Try
            WriteInfo("EBL_AcadLoader initalisieren ...")

            AddHandler docMgr.DocumentCreated, AddressOf DocumentCreated

            WriteInfo("... Ende AcLoader")

        Catch ex As System.Exception
            _TryReport.Show("unerwarteter Fehler in EBL_AcadLoader > Initialize", ex.ToString)
        End Try
    End Sub

    Public Sub Terminate() Implements IExtensionApplication.Terminate
    End Sub

when i clean clean complete to

 

 

    Public Sub Initialize() Implements IExtensionApplication.Initialize
        Try

        Catch ex As System.Exception
            _TryReport.Show("unerwarteter Fehler in EBL_AcadLoader > Initialize", ex.ToString)
        End Try
    End Sub

    Public Sub Terminate() Implements IExtensionApplication.Terminate
    End Sub

it will not works. Even no works, when reduce to min like

 

    Public Sub Initialize() Implements IExtensionApplication.Initialize
        Try

        Catch ex As System.Exception
            _TryReport.Show("unerwarteter Fehler in EBL_AcadLoader > Initialize", ex.ToString)
        End Try
    End Sub

 

 

but when i delete the Initialize- and Terminate-function AND Implements IExtensionApplication then the dll will be loaded!!

 

but now i missed the idea to get error-messages of the IExtensionApplication-Loading process.

 

could you help me?

 

reagards Jan

0 Likes
Message 4 of 11

SENL1362
Advisor
Advisor

As Norman said a few years ago always use try/catches in the events, but you have to be careful with the actions in the catch part, so do you also "catch" errors in your _TryReport.Show?.

You might try to surround the first catch with a nested try catch as well, like:

try

{

}

catch

{

    try

    {

        _TryReport.Show()

    }

    catch

    {

    }

} //end of first catch

 

0 Likes
Message 5 of 11

jan_tappenbeck
Collaborator
Collaborator

hi !

_TryReport.Show may be possible. but the error even Comes by

 

Implements IExtensionApplication

''' <summary>
''' Initalisierung der Funktion
''' </summary>
Public Sub Initialize() Implements IExtensionApplication.Initialize
End Sub

Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub

regards Jan

 

0 Likes
Message 6 of 11

SENL1362
Advisor
Advisor

What if you put the variable initializations in the Try catch block, i.e: all dim statements with "=", i.e.

 

try

{

_srvMisc= new EBL...

...

}

 

instead of

Private _LogMode As Boolean = True
    Private _SrvMisc As New EBL.Service.Miscellaneous
    Private _SrvLogin As New EBL.Service.LoginAD
    Private _TryReport As New EBL.Logger.TryCatchReport
    Private _Loader As New EBL_AcadLoader.Loader

 

 

0 Likes
Message 7 of 11

jan_tappenbeck
Collaborator
Collaborator

hi !

did i understand correct? now my code Looks like:

 

Implements IExtensionApplication

    Public Shared IsAcLoaderInit As Boolean = False
    Dim docMgr As DocumentCollection = Application.DocumentManager
    Private _Editor As Autodesk.AutoCAD.EditorInput.Editor
    Private _acDoc As Autodesk.AutoCAD.ApplicationServices.Document

    Private _LogMode As Boolean
    Private _SrvMisc As EBL.Service.Miscellaneous
    Private _SrvLogin As EBL.Service.LoginAD
    Private _TryReport As EBL.Logger.TryCatchReport
    Private _Loader As EBL_AcadLoader.Loader

    Private _TableName_Organisation As String = "X:\AcadKonfiguration\Organisation.db"
    Private _connDBOrga As SQLiteConnection = Nothing

    Private Sub SearchError()
        Dim ErrorMsg As String = ""
        Try
            ErrorMsg = "_LogMode"
            _LogMode = True
            ErrorMsg = "_SrvMisc"
            _SrvMisc = New EBL.Service.Miscellaneous
            ErrorMsg = "_SrvLogin"
            _SrvLogin = New EBL.Service.LoginAD
            ErrorMsg = "_TryReport"
            _TryReport = New EBL.Logger.TryCatchReport
            ErrorMsg = "_Loader"
            _Loader = New EBL_AcadLoader.Loader
        Catch ex As System.Exception
            MsgBox("ErrorAt:= " & ErrorMsg & vbCrLf & _
                ex.ToString)
        End Try

    End Sub

    ''' <summary>
    ''' Initalisierung der Funktion
    ''' </summary>
    Public Sub Initialize() Implements IExtensionApplication.Initialize
        SearchError()
    End Sub

but there will not show any error-message.

 

i try following test: when manuell load dll it was unable to delete - so the dll will beload.

 

is there a possiblity to try-catch "Implements IExtensionApplication"??

 

regards Jan

0 Likes
Message 8 of 11

SENL1362
Advisor
Advisor

The "execution" of you're DIM "=" statements  actions are done before Initialize(), thus without any try catch.

So if something goes wrong it's not catched, therefore i would put ALL these actions, (assignment/initialization except declaration) actions within the try/catch block

 

The extra SearchError procedure is not necessary.

I dont do VB anymore so i can't show you the exact VB code but

    'Private _TableName_Organisation As String = "X:\AcadKonfiguration\Organisation.db"
    'Private _connDBOrga As SQLiteConnection = Nothing
    Private _TableName_Organisation As String
    Private _connDBOrga As SQLiteConnection

 

    Public Sub Initialize() Implements IExtensionApplication.Initialize
        Dim ErrorMsg As String = ""
        Try
            _TableName_= "X:\AcadKonfiguration\Organisation.db"
            _connDBOrga  = Nothing

...

0 Likes
Message 9 of 11

norman.yuan
Mentor
Mentor

As @SENL1362 correctly pointed out, if yoru class implement IExtensionApplication.Initialize(), DO NOT declare your variable with "New" keyword, because when the DLL is loaded and the Initialze() is to run, AutoCAD will instantiate the class in application context, thus, any code in the class' constructor, or any member is declared like "Private xxx As New... " would run BEFORE Initialize(). This could potentially result in exception not being handled and make the DLL loading fail.

 

So, as my rule of thumb, if the DLL implements IExtensionApplication, I do not have code in the class' constructor, nor initialize any class-level member in declaration, do it in Initialize() with try...catch wrapped.

 

I did see you have removed "New" keyword from member declaration after @SENL1362's suggestion, but not sure why you still have the issue. You may try it from a clean project, and MAKE SURE ALL class members only initialized inside Initialze(), in your case, even something like docMgr, _Editor, _acDoc.... (in VB.NET, for variable of Object type, it default to Nothing when declared without "New" or "=").

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 10 of 11

jan_tappenbeck
Collaborator
Collaborator

i have pure and restructure the code less like

 

    Implements IExtensionApplication

    Public Shared IsAcLoaderInit As Boolean = False
    Dim docMgr As DocumentCollection = Application.DocumentManager
    Private _Editor As Autodesk.AutoCAD.EditorInput.Editor
    Private _acDoc As Autodesk.AutoCAD.ApplicationServices.Document

    ''' <summary>
    ''' Initalisierung der Funktion
    ''' </summary>
    Public Sub Initialize() Implements IExtensionApplication.Initialize
        ' Dim TryReport As New EBL.Logger.TryCatchReport
        Try
            WriteInfo("EBL_AcadLoader initalisieren ...")

            WriteInfo("Aufbau der DB-Verbindung ... Organisation")

            ''        ' HINWEIS 
            ''        ' Das Event wird erst registriert, nachdem das ERSTE Dokument KOMPLETT erstellt wurde !!!!
            CallLoader() ' deshalb muss hier die Anzahl zusätzlich ermittelt werden

            AddHandler docMgr.DocumentCreated, AddressOf DocumentCreated

            WriteInfo("Initalisierung abgeschlossen ...")
            WriteInfo("Weiter geht es mit den AutoCAD Ladefunktionen ...")

        Catch ex As System.Exception
            MsgBox("unerwarteter Fehler in EBL_AcadLoader > Initialize" & vbCrLf & ex.ToString)
            WriteInfo("unerwarteter Fehler in EBL_AcadLoader > Initialize" & vbCrLf & ex.ToString)
        End Try
    End Sub

and now it works - on the first machine before not works!

 

 

current i don't understand why!

 

thanks for help !

 

reagards Jan

0 Likes
Message 11 of 11

SENL1362
Advisor
Advisor

You did not supply any details, so it is next to impossible to guess where it goes wrong.

In general you must be careful with I/O and other "external" operations in Event Handlers.

Also  using IExtensionApplication comes with limitations because AutoCAD or it's documents might be in the progress of getting loaded. It may take some time to detect the problem(s).

 

I'll use the PerDocumentClass  as an alternative to get these global operations getting initialised.

0 Likes