471,325 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

GetEntryAssembly for default appdomain

Hi,

I was wondering if it was possible to get the Entry assembly for the
default application domain (and how to determine what the default app
domain is..).

I'd like to get to it for logging purposes, and it would be nice it the
object can discover that one its own, instead of trusting that a string
it was passed is actually the name of the application.

Thanks
Andy

Nov 28 '05 #1
4 3726
Andy wrote:
I was wondering if it was possible to get the Entry assembly for the
default application domain (and how to determine what the default app
domain is..).

I'd like to get to it for logging purposes, and it would be nice it
the object can discover that one its own, instead of trusting that a
string it was passed is actually the name of the application.


The problem is getting access to the default appdomain. If you call
Assembly.GetEntryAssembly for the default domain then you get the
process assembly, but if you call it on another appdomain then you get
the first assembly executed in that domain.

The frameworjk does not have a method to do this, but the unmanaged API
does:

http://winfx.msdn.microsoft.com/libr...asp?frame=true

Note that this is in the WinFX documentation, but this interface has
been available in all versions of the runtime - it's only now that they
have documented it.

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 4 '05 #2

"Andy" <aj********@capcitypress.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi,

I was wondering if it was possible to get the Entry assembly for the
default application domain (and how to determine what the default app
domain is..).

I'd like to get to it for logging purposes, and it would be nice it the
object can discover that one its own, instead of trusting that a string
it was passed is actually the name of the application.

Thanks
Andy


Following illustrates Richard's point.
// csc /r:icorruntimehost.dll runtimeuser.cs
using System;
using System.Runtime.InteropServices;

class Tester
{
static void Main()
{
ICorRuntimeHost corRuntimeHost;
object itfDefaultAD = null;

corRuntimeHost = (ICorRuntimeHost)new CorRuntimeHost();
corRuntimeHost.GetDefaultDomain(ref itfDefaultAD);
AppDomain defaultAppDomain = (AppDomain)itfDefaultAD;
Console.WriteLine(defaultAppDomain.FriendlyName);
defaultAppDomain.DoCallBack(new CrossAppDomainDelegate(MyCallBack));
}
static public void MyCallBack() {
string name = Assembly.GetEntryAssembly().FullName;
Console.WriteLine("from " + name);
}
}

[
// CLSID_CorRuntimeHost from MSCOREE.DLL
Guid("CB2F6723-AB3A-11d2-9C40-00C04FA30A3E"),
ComImport
]
public class CorRuntimeHost
{
}

[
// IID_ICorRuntimeHost
Guid("CB2F6722-AB3A-11d2-9C40-00C04FA30A3E"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )
]
// Only includes GetDefaultDomain's signature !!!
public interface ICorRuntimeHost
{
void CreateLogicalThreadState();
void DeleteLogicalThreadState();
void SwitchInLogicalThreadState();
void SwitchOutLogicalThreadState();
void LocksHeldByLogicalThread();
void MapFile();
void GetConfiguration();
void Start();
void Stop();
void CreateDomain();
void GetDefaultDomain([MarshalAs(UnmanagedType.IUnknown)]ref Object o);
void EnumDomains();
void NextDomain();
void CloseEnum();
void CreateDomainEx();
void CreateDomainSetup();
void CreateEvidence();
void UnloadDomain();
void CurrentDomain();
}

Willy.
Dec 4 '05 #3
Great, thanks to both of you for responding! Hopefully this can be
done in managed code in 2.0. I'll have to investiage.

Andy

Dec 5 '05 #4

"Andy" <aj********@capcitypress.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Great, thanks to both of you for responding! Hopefully this can be
done in managed code in 2.0. I'll have to investiage.

Andy


The sample I've posted is for V2, don't know if it works for v1.x.

Willy.
Dec 5 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by SS | last post: by
reply views Thread by Sean Hederman | last post: by
8 posts views Thread by Bern McCarty | last post: by
reply views Thread by Adnan Selimovic | last post: by
2 posts views Thread by siger99 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.