473,794 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get hte Assembly when...

Hi,

I have a form (A) which has a collection as a property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(fiel d,BindingFlags. Instance |
BindingFlags.No nPublic | BindingFlags.Pu blic | BindingFlags.St atic |
BindingFlags.Fl attenHierarchy) ;
if(parameterInf o == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form)
because its where the collection was called so then the field is never
found. Form A (bas form) is in another assembly/solution. All this has to be
done is design time and not runtime. How can I get the fileds or assembly of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

Nov 15 '05 #1
5 1637
I've recreated the situation you've described and haven't
encountered any errors. Perhaps I misunderstood your
problem, so let me explain what I did:

Assembly One
Defines OriginClass with one method, "public string Test
()". "Test" simply uses the code from your example and
returns either the parameterInfo.N ame or "Field Not Found"

Assembly Two
Defines DerivedClass which inherits from OriginClass

Assembly Three
Defines a third assembly that defines a DerivedClass
object and calls its "Test" method (which is actually the
method from OriginClass).

Does this accurately model your situation?

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
-----Original Message-----
Hi,

I have a form (A) which has a collection as a property. All my formsinhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo fromthe form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField (field,BindingF lags.Instance |BindingFlags.N onPublic | BindingFlags.Pu blic | BindingFlags.St atic |BindingFlags.F lattenHierarchy );
if(parameterIn fo == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form)because its where the collection was called so then the field is neverfound. Form A (bas form) is in another assembly/solution. All this has to bedone is design time and not runtime. How can I get the fileds or assembly ofthe current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

.

Nov 15 '05 #2
Jerry,

Yes it does but I'm calling a collection in design time this is where
the problem occurs. It is at design time I want to get the field info from
the derived class. When I execute the code from the parameterInfo.. .. that
is in the OriginClass... it is looking for the fields in Assembly One and
not Assembly Three... al this at design time.

Regards
Lucas

"Jerry Negrelli" <je************ @nospam.datasci entific.com> wrote in message
news:07******** *************** *****@phx.gbl.. .
I've recreated the situation you've described and haven't
encountered any errors. Perhaps I misunderstood your
problem, so let me explain what I did:

Assembly One
Defines OriginClass with one method, "public string Test
()". "Test" simply uses the code from your example and
returns either the parameterInfo.N ame or "Field Not Found"

Assembly Two
Defines DerivedClass which inherits from OriginClass

Assembly Three
Defines a third assembly that defines a DerivedClass
object and calls its "Test" method (which is actually the
method from OriginClass).

Does this accurately model your situation?

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
-----Original Message-----
Hi,

I have a form (A) which has a collection as a

property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get

the fieldInfo from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField

(field,BindingF lags.Instance |
BindingFlags.N onPublic | BindingFlags.Pu blic |

BindingFlags.St atic |
BindingFlags.F lattenHierarchy );
if(parameterIn fo == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from

Form A (base form)
because its where the collection was called so then the

field is never
found. Form A (bas form) is in another

assembly/solution. All this has to be
done is design time and not runtime. How can I get the

fileds or assembly of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

.

Nov 15 '05 #3
Maybe I'm not uderstanding you correctly, but I think you're looking in the
wrong place for the property. Does this code work for you:

// Assembly1.cs
public class BaseClass
{
int SomeField;
void Test() {
Type t = this.GetType(); // I think this is wrong
t = typeof(BaseClas s); // Try this instead
FieldInfo parameterInfo = t.GetField(fiel d,BindingFlags. Instance |
BindingFlags.No nPublic | BindingFlags.Pu blic | BindingFlags.St atic |
BindingFlags.Fl attenHierarchy) ;
if(parameterInf o == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field not found");
fieldFound = false;
}
}
}
}

// Assembly2.cs
public class DerivedClass : BaseClass
{
}

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
"Lucas Sain" <ls***@lidersof t.com> wrote in message
news:uL******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a form (A) which has a collection as a property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo from the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(fiel d,BindingFlags. Instance |
BindingFlags.No nPublic | BindingFlags.Pu blic | BindingFlags.St atic |
BindingFlags.Fl attenHierarchy) ;
if(parameterInf o == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form)
because its where the collection was called so then the field is never
found. Form A (bas form) is in another assembly/solution. All this has to be done is design time and not runtime. How can I get the fileds or assembly of the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas

Nov 15 '05 #4
Grant,
Thanks for your Reply.
BaseClass has a method (BaseMehtod) that searches X control on a form
(The code I wrote before).
The problem is that in the DerivedClass I have added some Controls which
I want the BaseMethod to be able to reflect at design time because all this
validation should occure at design time, so if I use your sugestion I only
get the type of the BaseClass so no fields are found. All the fields are in
the DerivedClass.

Am I doins something wrong or am I missing something....

Regards
Lucas Sain


"Grant Richins [MS]" <gr*****@online .microsoft.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
Maybe I'm not uderstanding you correctly, but I think you're looking in the wrong place for the property. Does this code work for you:

// Assembly1.cs
public class BaseClass
{
int SomeField;
void Test() {
Type t = this.GetType(); // I think this is wrong
t = typeof(BaseClas s); // Try this instead
FieldInfo parameterInfo = t.GetField(fiel d,BindingFlags. Instance |
BindingFlags.No nPublic | BindingFlags.Pu blic | BindingFlags.St atic | BindingFlags.Fl attenHierarchy) ;
if(parameterInf o == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field not found");
fieldFound = false;
}
}
}
}

// Assembly2.cs
public class DerivedClass : BaseClass
{
}

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.

"Lucas Sain" <ls***@lidersof t.com> wrote in message
news:uL******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a form (A) which has a collection as a property. All my forms
inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(fiel d,BindingFlags. Instance |
BindingFlags.No nPublic | BindingFlags.Pu blic | BindingFlags.St atic |
BindingFlags.Fl attenHierarchy) ;
if(parameterInf o == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base form) because its where the collection was called so then the field is never
found. Form A (bas form) is in another assembly/solution. All this has

to be
done is design time and not runtime. How can I get the fileds or
assembly of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas


Nov 15 '05 #5
Ahhhh! Well, design time is an entirely different beast and well out of my
league.

So you have something like this:
//assembly 1
class BaseClass {
void EnumDerivedFiel ds() {
// code here to find "SomeField" ?
}
}

//assembly 2
class DerviedClass : BaseClass {
int SomeField;
}
So basically you have a base class that somehow needs to change according to
which specific derived class instance it is? It sounds like what you should
really be doing is having more virtual methods or properties in the derived
classes...
--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
"Lucas Sain" <ls***@lidersof t.com> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
Grant,
Thanks for your Reply.
BaseClass has a method (BaseMehtod) that searches X control on a form
(The code I wrote before).
The problem is that in the DerivedClass I have added some Controls which I want the BaseMethod to be able to reflect at design time because all this validation should occure at design time, so if I use your sugestion I only
get the type of the BaseClass so no fields are found. All the fields are in the DerivedClass.

Am I doins something wrong or am I missing something....

Regards
Lucas Sain


"Grant Richins [MS]" <gr*****@online .microsoft.com> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
Maybe I'm not uderstanding you correctly, but I think you're looking in the
wrong place for the property. Does this code work for you:

// Assembly1.cs
public class BaseClass
{
int SomeField;
void Test() {
Type t = this.GetType(); // I think this is wrong
t = typeof(BaseClas s); // Try this instead
FieldInfo parameterInfo = t.GetField(fiel d,BindingFlags. Instance |
BindingFlags.No nPublic | BindingFlags.Pu blic |

BindingFlags.St atic |
BindingFlags.Fl attenHierarchy) ;
if(parameterInf o == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field not found");
fieldFound = false;
}
}
}
}

// Assembly2.cs
public class DerivedClass : BaseClass
{
}

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no

rights.


"Lucas Sain" <ls***@lidersof t.com> wrote in message
news:uL******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I have a form (A) which has a collection as a property. All my forms inhert from this base form.

I'm tring to put some code in form A where I can get the fieldInfo

from
the form that imnherits from A. This is the code:

Type t = this.GetType();
FieldInfo parameterInfo = t.GetField(fiel d,BindingFlags. Instance |
BindingFlags.No nPublic | BindingFlags.Pu blic | BindingFlags.St atic |
BindingFlags.Fl attenHierarchy) ;
if(parameterInf o == null)
{
if(Assembly.Get EntryAssembly() != null )
{
MessageBox.Show ("Field nod found");
fieldFound = false;
}
}

The problem with this is that it gets the Assembly from Form A (base

form) because its where the collection was called so then the field is never found. Form A (bas form) is in another assembly/solution. All this has

to
be
done is design time and not runtime. How can I get the fileds or

assembly
of
the current form and not the inhertided form.

I hope I made my self clear..

Regards
Lucas



Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2339
by: Daylor | last post by:
can shadowcopy be done with private assembly ? any info about how shadowcopy actually works ? when im compiling an assembly (while the assembly file is in use ), what i need to do ? change vertion ? change name of file ? how the appDomain will know to load the new assembly ?
26
10553
by: nospam | last post by:
Just wondering, What do you think the difference in performance would be between (1.) Compiled C# (2.) Compiled C++ (3.) and Assembly Language And how would the mix be if some if any of these languages had to hit against a SQL Server database
2
6408
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this to happen we had to change the context in which asp.net runs from machine to SYSTEM by modifying the machine.config file. Under Windows 2003 no matter how asp.net is set to run as either machine or system. I get the following error: ...
2
1627
by: Theodore | last post by:
Hi, from within an executable I am calling class A located in a dll file which in turn calls class B located in another dll file. I want class B to be able to resolve the last entry assembly. By calling the ExecutingAssembly i am getting Class B assembly, if i call the CallingAssembly i get back the System.Windows.Forms Assembly and finally if a call the GetEntryAssembly i get the assembly of the executable. So how can i get the Class A...
3
1517
by: DDE | last post by:
Hi everybody, I developed an assembly common to all my Web Services, so I registered it and put it in the Global Assembly Cache. Now, I modified this assembly, but cannot succed to have this new assembly used by my Web Services. Whatever I do, the old assembly is still used!! I try to unregister it, put the new version in the assembly cache nothing works. I also repplaced the dll fil in :\WINNT\Microsoft.NET\Framework\v1.1.4322 , same...
10
3484
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
2
1883
by: john | last post by:
Maybe I haven't had that "a-ha" moment yet, but I think the new approach to web projects is a step in the wrong direction. My main beef is that control over the assembly generation process has been taken away from us! I also don't agree with the logic behind a web site not having a project file, but I'll save that for another thread! Here's our scenario: We have a web project that runs in a non-managed sharepoint directory. The web...
3
4414
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
1
2370
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been installed into the GAC. We originally had this assembly without a strong-name and we were successfully using it by referencing it when it was NOT in the GAC. The assembly was built using the 1.0 framework and we were able to call it from both 1.0...
14
2669
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both reference the same BLL in a separate assembly, and I have all three projects in a single solution file for development, with the two UI's each having a project reference to the BLL assembly. I created a Setup and Deployment package for the winform app...
0
9672
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
10435
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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
10000
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...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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...
1
4113
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
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.