Groups | Blog | Home
all groups > dotnet interop > april 2004 >

dotnet interop : Equivalent of App.path



Harish
4/13/2004 10:51:02 AM
What is the equivalent of app.path?? I have a .NET DLL and it uses an INI file to get application related information. In Vb6, this INI file is stored along with the DLL directory(ex: D:\myapp\myapp.ini). I have strong named the DLL and put it in the GAC. So if I take GetExecutingAssembly().location, I am getting the c:\windows\GAC\(publickeytoken)\mydll.dll.

Is there any way to get to the 'D:\myapp\myapp.dll' path without hard coding the same?

If I don't want to use an INI what would be the best alternate approach? I tried app.config and they do not work correctly with DLLs. Also, I will be instantiating this DLL from SQL server procedure using sp_oacreate. So I cannot use Application.startuppath

Please help

Paul Clement
4/14/2004 11:33:23 AM
[quoted text, click to view]

¤ What is the equivalent of app.path?? I have a .NET DLL and it uses an INI file to get application related information. In Vb6, this INI file is stored along with the DLL directory(ex: D:\myapp\myapp.ini). I have strong named the DLL and put it in the GAC. So if I take GetExecutingAssembly().location, I am getting the c:\windows\GAC\(publickeytoken)\mydll.dll.
¤
¤ Is there any way to get to the 'D:\myapp\myapp.dll' path without hard coding the same??
¤
¤ If I don't want to use an INI what would be the best alternate approach? I tried app.config and they do not work correctly with DLLs. Also, I will be instantiating this DLL from SQL server procedure using sp_oacreate. So I cannot use Application.startuppath.
¤

If I understand correctly what you are asking, have you tried Assembly.CodeBase?


Paul ~~~ pclement@ameritech.net
Harish
4/16/2004 4:01:06 PM
Hi Paul

Thanks a lot for looking into this. I tried your suggestion. Infact this is exactly what I want. Please tell me what I am doing wrong. I am still getting the GAC path after the code change. Here is the code from my dll

public sub getpath(byref strpath as string
Dim currAssembly As System.Reflection.Assembl

currAssembly = System.Reflection.Assembly.GetExecutingAssembly(
strPath = currAssembly.CodeBas
currAssembly = nothin
end su
Paul Clement
4/19/2004 9:58:30 AM
[quoted text, click to view]

¤ Hi Paul,
¤
¤ Thanks a lot for looking into this. I tried your suggestion. Infact this is exactly what I want. Please tell me what I am doing wrong. I am still getting the GAC path after the code change. Here is the code from my dll.
¤
¤ public sub getpath(byref strpath as string)
¤ Dim currAssembly As System.Reflection.Assembly
¤
¤ currAssembly = System.Reflection.Assembly.GetExecutingAssembly()
¤ strPath = currAssembly.CodeBase
¤ currAssembly = nothing
¤ end sub

Did you try the example in the documentation?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemreflectionassemblyclasscodebasetopic.asp


Paul ~~~ pclement@ameritech.net
Harish
4/19/2004 3:26:04 PM
Hi Paul
I changed my code like this as per that MSDN link. But I still got the GAC path. Did I make any mistake in the code
Here is the code

Thanks
Haris
Dim SampleAssembly As [Assembly
' Instantiate a target object
Dim Integer1 As New Int3
Dim curobj As New WaterMark.clsWaterMar
Dim Type1 As Typ
' Set the Type instance to the target class type
Type1 = curobj.GetType(
' Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = [Assembly].GetAssembly(Type1
' Gets the location of the assembly using file: protocol
strPath = SampleAssembly.CodeBas

SampleAssembly = Nothin
Paul Clement
4/21/2004 9:05:20 AM
[quoted text, click to view]

¤ Hi Paul,
¤ I changed my code like this as per that MSDN link. But I still got the GAC path. Did I make any mistake in the code?
¤ Here is the code.
¤
¤ Thanks,
¤ Harish
¤ Dim SampleAssembly As [Assembly]
¤ ' Instantiate a target object.
¤ Dim Integer1 As New Int32
¤ Dim curobj As New WaterMark.clsWaterMark
¤ Dim Type1 As Type
¤ ' Set the Type instance to the target class type.
¤ Type1 = curobj.GetType()
¤ ' Instantiate an Assembly class to the assembly housing the Integer type.
¤ SampleAssembly = [Assembly].GetAssembly(Type1)
¤ ' Gets the location of the assembly using file: protocol.
¤ strPath = SampleAssembly.CodeBase
¤
¤ SampleAssembly = Nothing
¤ curobj = Nothing

The code looks OK. I will take a look at this to see if it is the correct approach.


Paul ~~~ pclement@ameritech.net
mani
4/22/2004 11:47:05 PM

Hi


App.path equivalent to "System.Windows.Forms.Application.StartupPath"


Public gv_sDbfPath As String = System.Windows.Forms.Application.StartupPath & "\config.dll"


-Mani

---
sybil5000 NO[at]SPAM yahoo.com
5/14/2004 2:40:59 PM
[quoted text, click to view]


Unfortunately, not true if used within a referenced DLL.

If I make a vb6 app, c:\test1\tester.exe
that references a C# DLL (or its typelibrary), c:\CS\Test2\testit.dll,

System.Windows.Forms.Application.StartupPath will return "c:\test1".

I've been looking for something that will return "C:\CS\Test2". Not
the GAC, and not the path of the app I'm referencing my DLL from. All
sybil5000 NO[at]SPAM yahoo.com
5/14/2004 2:49:36 PM
[quoted text, click to view]

Hi --

I'm latching onto this thread because I'm having the same problem. All
the permutations I've seen of Assembly.GetExecutingAssembly() return a
path that has something to do with the GAC.

I have a C# DLL that I put in
C:\SourceCode\CS\TestInterop\TestInterop.dll, that exposes a public
class Main, and in that class is a public method called FindMe. FindMe
returns a string that points to the location of the DLL. Formerly I
would have used App.Path. But now that's gone :(

I used regasm to create a typelibrary, and I used gacutil.

From VB6 I want to be able to go:

dim o as Object
set o = CreateObject("TestInterop.Main")
msgbox o.FindMe

Torsten Rendelmann
6/18/2004 10:05:46 AM
Try this:

Console.WriteLine("GetExecutingAssembly.Location=" +
Assembly.GetExecutingAssembly().Location);

TorstenR

[quoted text, click to view]
AddThis Social Bookmark Button