Inherited form problem

K

Ken

This problem occurs when I try to open the form in the designer.

I have form A that contains a method that is called in the OnLoad event.
This method contains the following line:
Assembly Asmbly = Assembly.GetEntryAssembly ( );
Then proceeds to use properties from Asmbly.
I am using this to load the Copyright, and version from the EXE into private
fields.

I have form B that inherits from form A. When I try to open form B in the
designer I get the following message:

An error occurred while loading the document. Fix the error, and try
loading the document again. The error message follows:

Value cannot be null.
Parameter name: element

I believe that this message is caused by the GetEntryAssembly call. If I
comment out the call to the method that calls GetEntryAssembly. It works
fine.

Is there another way to do this, or does anyone have a work around?

Thanks

Ken
 
K

Ken

I want to get the Assembly properties for the .EXE. These forms live in a
DLL.
GetEntryAssembly returns a reference to the assembly which is the process
executeable.

For some reason when the IDE loads the form this call causes the described
error.

Ken
 
I

Iulian Ionescu

I believe that you should test for DesignMode and if yes
avoid calling any calling or entry assembly query. That
is because at design time it is not your assembly that
has the entry point but actually the VS IDE. I mean, this
is what i heard... To load copyright info and other
similar things you should better use a licensing scheme...

I have to see if I can find an older posting about this,
but I thin this is what happens...

take care,
iulian
 
Y

Ying-Shen Yu[MSFT]

Hi Ken,
Seems like the GetEntryAssembly returns null in design-time,
If you just want to get the attribute in run-time, you may check the
DesignMode property before calling this method.If you want to ge the
attribute in design-time, you may try the ITypeResolutionService and use
the GetAssembly method.
Note, you should The fullpath "namespace.typename" to the method.

If you still have problem on this issue, please be free to post it on this
group.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "Ken" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Subject: Inherited form problem
| Date: Mon, 27 Oct 2003 15:10:43 -0500
| Organization: Posted via Supernews, http://www.supernews.com
| Message-ID: <[email protected]>
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| X-Complaints-To: (e-mail address removed)
| Lines: 29
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-01!sn-
post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:55320
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| This problem occurs when I try to open the form in the designer.
|
| I have form A that contains a method that is called in the OnLoad event.
| This method contains the following line:
| Assembly Asmbly = Assembly.GetEntryAssembly ( );
| Then proceeds to use properties from Asmbly.
| I am using this to load the Copyright, and version from the EXE into
private
| fields.
|
| I have form B that inherits from form A. When I try to open form B in the
| designer I get the following message:
|
| An error occurred while loading the document. Fix the error, and try
| loading the document again. The error message follows:
|
| Value cannot be null.
| Parameter name: element
|
| I believe that this message is caused by the GetEntryAssembly call. If I
| comment out the call to the method that calls GetEntryAssembly. It works
| fine.
|
| Is there another way to do this, or does anyone have a work around?
|
| Thanks
|
| Ken
|
|
|
 
K

Ken

Thanks to all who replied. Ying-Shen Yu's answer helped me resolve the
issue. I wrapped the code that uses the assembly reference returned from
Assembly.GetEntryAssembly ( ) in an if statemement that tests if the
reference is null. If not it uses the reference, otherwise it does not.

Ken
 

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