Get the parent assembly

  • Thread starter Thread starter Darren Green
  • Start date Start date
D

Darren Green

Hi,

I have written a custom control, but in that control's code I want to
reference the assembly for the application that uses my control.

GetExecutingAssembly just gives me my control's assembly, which seems
sensible, but not what I want. I also tried GetCallingAssembly, but this
came up with MS framework, System.Windows.Forms.dll

How can I get the assembly that is using my control?

(Using Whidbey in case there is some fancy new way of doing this)

Cheers
 
GetEntryAssembly?

Assuming you want the windows forms app that created your control that should work

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

I have written a custom control, but in that control's code I want to
reference the assembly for the application that uses my control.

GetExecutingAssembly just gives me my control's assembly, which seems
sensible, but not what I want. I also tried GetCallingAssembly, but this
came up with MS framework, System.Windows.Forms.dll

How can I get the assembly that is using my control?

(Using Whidbey in case there is some fancy new way of doing this)

Cheers
 
Hi Darren,

In addition to Richard's suggestion on the "GetEntryAssembly" ,you may also
try the "GetCallingAssembly" which may also help. And seems currently we
only have the two means to get the upper stream assembly.
If the parent assembly is the main assembly of that applcation, then the
GetEntryAssembly can do it well.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Another possibility is to get the Windows form that is hosting your control.

System.Windows.Forms.Form parentForm = FindForm();

if ( parentForm != null )
{
System.Type classType = parentForm.GetType();
System.Assembly classAssembly = classType.Assembly;
}

Hope that helps

Matt Osborne
 
mageos said:
Another possibility is to get the Windows form that is hosting your control.

System.Windows.Forms.Form parentForm = FindForm();

if ( parentForm != null )
{
System.Type classType = parentForm.GetType();
System.Assembly classAssembly = classType.Assembly;
}

Hope that helps

Matt Osborne


Richard, GetEntryAssembly doesn't work, since my app is actually a
component hosted inside another, sorry should have mentioned this.

Steven, GetCallingAssembly gave me the MS framework,
System.Windows.Forms.dll

Matt, you're the man. Works treat.

Thank you all.
 
Thanks for your followup, Darren,

Glad that you've got the correct approach. Also, thanks for Matt's great
ideas.
Have a good day.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top