473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 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 3869
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SS | last post by:
Assembly.GetEntryAssembly(); is returning null in asp.net. it works fine with Win apps. How to get the entry assembly in web apps
0
by: Sean Hederman | last post by:
I've got a couple of things I'm not sure in my mind about as far as the options to CorBindToRuntimeEx go: 1. Is the default option for Windows Forms is...
2
by: Martin Lapierre | last post by:
How can I remove the default exception handler handler? When adding a custom handler, I can't get rid of the VS.NET unhandled exception dialog. Ex: AppDomain currentDomain =...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
0
by: Adnan Selimovic | last post by:
Hi folks! In which circumstances does this method return null. Assembly.GetEntryAssembly() I have two web application DLLs. The first is calling a method in the second one. The...
0
by: Daylor | last post by:
hi. how can i set the AppDomain.BaseDirectory to the default appdomain ? (i dont want /need to create new appdomain )
2
by: JohnH | last post by:
Hi, Does anyone know why the DomainUnload is not raised for the default AppDomain. I'm trying to get some shutdown code in a dynamically loaded assembly called before the application shuts...
2
by: Dave Burns | last post by:
Hello, We have a situation where a managed C++ assembly links with native C++ dll. There is a callback mechanism which calls back into the managed code asynchronously. Since native classes...
2
by: siger99 | last post by:
Hi, I try to use a 3rd party assembly ( basically a layer of managed C++ around a native C++ lib). Unfortunately, it was developped for NET 1.1 and knows only the default AppDomain. When I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.