Get the parent assembly

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
 
R

Richard Blewett [DevelopMentor]

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
 
S

Steven Cheng[MSFT]

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.)
 
M

mageos

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
 
D

Darren Green

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.
 
S

Steven Cheng[MSFT]

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.)
 

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

Top