GetEntryAssembly for default appdomain

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

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
 
Andy said:
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/lib...fc-f335-4aae-9bb0-c3e1271a9426.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
 
Andy said:
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.
 
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
 
Andy said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top