473,811 Members | 2,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetEntryAssembl y 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 3896
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.GetEnt ryAssembly 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********@cap citypress.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.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:icorruntimeho st.dll runtimeuser.cs
using System;
using System.Runtime. InteropServices ;

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

corRuntimeHost = (ICorRuntimeHos t)new CorRuntimeHost( );
corRuntimeHost. GetDefaultDomai n(ref itfDefaultAD);
AppDomain defaultAppDomai n = (AppDomain)itfD efaultAD;
Console.WriteLi ne(defaultAppDo main.FriendlyNa me);
defaultAppDomai n.DoCallBack(ne w CrossAppDomainD elegate(MyCallB ack));
}
static public void MyCallBack() {
string name = Assembly.GetEnt ryAssembly().Fu llName;
Console.WriteLi ne("from " + name);
}
}

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

[
// IID_ICorRuntime Host
Guid("CB2F6722-AB3A-11d2-9C40-00C04FA30A3E"),
InterfaceType(C omInterfaceType .InterfaceIsIUn known)
]
// Only includes GetDefaultDomai n's signature !!!
public interface ICorRuntimeHost
{
void CreateLogicalTh readState();
void DeleteLogicalTh readState();
void SwitchInLogical ThreadState();
void SwitchOutLogica lThreadState();
void LocksHeldByLogi calThread();
void MapFile();
void GetConfiguratio n();
void Start();
void Stop();
void CreateDomain();
void GetDefaultDomai n([MarshalAs(Unman agedType.IUnkno wn)]ref Object o);
void EnumDomains();
void NextDomain();
void CloseEnum();
void CreateDomainEx( );
void CreateDomainSet up();
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********@cap citypress.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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
571
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
1375
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 STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST? 2. If I start the default domain using STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST, create a child AppDomain using LoaderOptimization.MultiDomain, and then load a non-strong named assembly into the Child Domain, does it get loaded...
2
4825
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 = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); MyHandler gets called AFTER the default VS.NET unhandled exception handler
8
3522
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 cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
0
1605
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 GetEntryAssembly() method returns null if called in the second assembly Cheers,
0
984
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
3602
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 down. I tried adding a handler for the DomainUnload event to the AppDomain.CurrentDomain, but this does not get raised because it is the
2
2319
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 cannot hold onto a managed reference, we need to have a managed static member which we access during the callback and then get into the managed code. This works great in a console or WinForm app. But in ASP.NET it doesn't. The reason is that each...
2
3475
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 try to call it from another AppDomain, I get the "Cannot pass a GCHandle across AppDomains" error.
0
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10408
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9211
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.