ExecName() behaviour

This forum is meant for questions and discussions about the X# language and tools
Post Reply
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

ExecName() behaviour

Post by Karl-Heinz »

Guys,

i´m using the VO LogFile class and noticed that the ExecName() func doesn´t work as expected.

oLog := LogFile { "" , FALSE , TRUE }

If no path+file name is given the Logfile init() creates the logfile path+name by calling ExecName(true). Then the extension is removed and "log" added. But because the ExecName() func is part of the XSharp core dll the Logfile points to the GAC dir:

"C:windows...v4.0_2.0.0.9__ed555a0467764586XSharp.Core.log" - :woohoo:

Responsible for that is the core _ExecName() function which uses:

System.Reflection.Assembly.GetExecutingAssembly():Location

As a workaround I created the 2 funcs below and placed them in a DLL. Now, if ExecName2() is called within my exe the created path+file name is the same as with VO. Are there any pitfalls if "System.Reflection.Assembly.GetExecutingAssembly():Location" is simply replaced with "System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName" ?

Code: Select all


// ----------- DLL code ---

 STATIC METHOD _ExecName2()  AS STRING	
 RETURN System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// instead of the currently used:
// RETURN System.Reflection.Assembly.GetExecutingAssembly():Location

// -------- 	
 
 STATIC METHOD ExecName2( lFull AS LOGIC )  AS STRING
    LOCAL   nPos        AS DWORD
    LOCAL   cPath       AS STRING

    cPath := _ExecName2()

    IF ! lFull
        nPos  := RAt( "", cPath )

        IF nPos != 0
            cPath := SubStr2( cPath, nPos + 1 )
        ENDIF
    ENDIF

RETURN cPath    
regards
Karl-Heinz
User avatar
lumberjack
Posts: 726
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

ExecName() behaviour

Post by lumberjack »

Karl-Heinz wrote:Guys,
oLog := LogFile { "" , FALSE , TRUE }
I will never trust that rather do:

Code: Select all

oLog := LogFile { Application.ExecutablePath, FALSE , TRUE }
Regards,
______________________
Johan Nel
Boshof, South Africa
User avatar
Chris
Posts: 4854
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

ExecName() behaviour

Post by Chris »

Hi Karl-Heinz,

Instead of GetExecutingAssembly(), it should had been GetEntryAssembly(). Although as you say, there are more ways to obtain this directory. And one of the very good things with X# and .Net in general, is that we can do a little search in the web for the best option, advantages and disadvantages of all methods, which one people suggest to use, and all replies will apply to all the .Net languages, including X# of course. That's exactly what I will do right now, to make sure that using GetEntryAssembly() is the correct way to do it!

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply