473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Assembly problem

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 assembly?

Thanks
Theodore

Jul 22 '05 #1
2 1595
You need to use GetCallingAssembly. The reason this is returning System.Windows.Forms is that the method you are calling
GetCallingAssembly in is being invoked directly from the System.Windows.Forms assembly. This is probably because you are handling a
Control event and the delegate you registered is being invoked by the Control, which is located in the System.Windows.Forms
assembly.

To get GetCallingAssembly to return the assembly that you want, you should save a reference to that assembly when the class is
constructed as long as the constructor is being invoked by assembly A. If A does not construct the object in B, then you should
implement an Initialize() method that A may call:

// in Assembly 'A'
class A
{
// When 'A' constructs 'B':
public A()
{
B = new B();
}

// When 'A' is passed a reference of 'B':
public A(B b)
{
b.Initialize(this.GetType().Assembly);
}
}

// in Assembly 'B'
class B
{
System.Runtime.Reflection.Assembly callingAssembly;

public B()
{
callingAssembly = System.Runtime.Reflection.Assembly.GetCallingAssem bly();
}

// This is another option. Performing this task explicitly:
public B(System.Runtime.Reflection.Assembly caller)
{
if (caller == null)
throw new ArgumentNullException("caller");

callingAssembly = caller;
}

// Yet another option if class 'A' was not the object that constructed an instance of 'B':
public void Initialize(System.Runtime.Reflection.Assembly caller)
{
if (caller == null)
throw new ArgumentNullException("caller");

callingAssembly = caller;
}
}
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Theodore" <t@t.t> wrote in message news:uu**************@TK2MSFTNGP10.phx.gbl...
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 assembly?

Thanks
Theodore

Jul 22 '05 #2
Dave,

thanks a lot!
You saved my day and a lot of wasted time....

Theodore

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
You need to use GetCallingAssembly. The reason this is returning
System.Windows.Forms is that the method you are calling GetCallingAssembly
in is being invoked directly from the System.Windows.Forms assembly. This
is probably because you are handling a Control event and the delegate you
registered is being invoked by the Control, which is located in the
System.Windows.Forms assembly.

To get GetCallingAssembly to return the assembly that you want, you should
save a reference to that assembly when the class is constructed as long as
the constructor is being invoked by assembly A. If A does not construct
the object in B, then you should implement an Initialize() method that A
may call:

// in Assembly 'A'
class A
{
// When 'A' constructs 'B':
public A()
{
B = new B();
}

// When 'A' is passed a reference of 'B':
public A(B b)
{
b.Initialize(this.GetType().Assembly);
}
}

// in Assembly 'B'
class B
{
System.Runtime.Reflection.Assembly callingAssembly;

public B()
{
callingAssembly =
System.Runtime.Reflection.Assembly.GetCallingAssem bly();
}

// This is another option. Performing this task explicitly:
public B(System.Runtime.Reflection.Assembly caller)
{
if (caller == null)
throw new ArgumentNullException("caller");

callingAssembly = caller;
}

// Yet another option if class 'A' was not the object that constructed
an instance of 'B':
public void Initialize(System.Runtime.Reflection.Assembly caller)
{
if (caller == null)
throw new ArgumentNullException("caller");

callingAssembly = caller;
}
}
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Theodore" <t@t.t> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
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 assembly?

Thanks
Theodore


Jul 22 '05 #3

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

Similar topics

1
by: Paul Klanderud | last post by:
I'm having a problem with being unable to remove a reference to an old, nonexistent version of a strongly- named assembly. I should mention that my issues arose at the same time I upgraded from...
2
by: Peter Gomis | last post by:
I have encountered a situation where I am unable to remove a .NET assembly from the GAC. The message I receive is "Assembly 'assemblyname' could not be uninstalled because it is required by other...
0
by: Ken Durden | last post by:
I'm working on a client-server application where the client is controlling two devices (aka servers) which both implement the same interface contract. We have a set of about 4 assemblies which...
5
by: Lucas Sain | last post by:
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...
4
by: V. Jenks | last post by:
I'm using reflection to dynamically load an assembly and even though I'm sure the assembly is present, I keep getting an error telling me the "assembly or one of its references can't be found". ...
2
by: Andrew Jocelyn | last post by:
Hi I get this error when I change something in the web.config file. When I build the VS projects and load the first web page the application runs fine. If I then make a save the web.config file...
3
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...
1
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...
14
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...
0
by: Andy | last post by:
Thanks Peter, I thought I'd give an update on this problem. My application had 2 assemblies that contained classed for the Data access and business logic layer. It was on one of them that I was...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.