473,783 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ExecutingAssemb ly 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 GetEntryAssembl y i
get the assembly of the executable.
So how can i get the Class A assembly?

Thanks
Theodore

Jul 22 '05 #1
2 1625
You need to use GetCallingAssem bly. The reason this is returning System.Windows. Forms is that the method you are calling
GetCallingAssem bly 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 GetCallingAssem bly 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(th is.GetType().As sembly);
}
}

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

public B()
{
callingAssembly = System.Runtime. Reflection.Asse mbly.GetCalling Assembly();
}

// This is another option. Performing this task explicitly:
public B(System.Runtim e.Reflection.As sembly caller)
{
if (caller == null)
throw new ArgumentNullExc eption("caller" );

callingAssembly = caller;
}

// Yet another option if class 'A' was not the object that constructed an instance of 'B':
public void Initialize(Syst em.Runtime.Refl ection.Assembly caller)
{
if (caller == null)
throw new ArgumentNullExc eption("caller" );

callingAssembly = caller;
}
}
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Theodore" <t@t.t> wrote in message news:uu******** ******@TK2MSFTN GP10.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 ExecutingAssemb ly 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 GetEntryAssembl y 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*********@do tcomdatasolutio ns.com> wrote in message
news:uK******** ******@tk2msftn gp13.phx.gbl...
You need to use GetCallingAssem bly. The reason this is returning
System.Windows. Forms is that the method you are calling GetCallingAssem bly
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 GetCallingAssem bly 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(th is.GetType().As sembly);
}
}

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

public B()
{
callingAssembly =
System.Runtime. Reflection.Asse mbly.GetCalling Assembly();
}

// This is another option. Performing this task explicitly:
public B(System.Runtim e.Reflection.As sembly caller)
{
if (caller == null)
throw new ArgumentNullExc eption("caller" );

callingAssembly = caller;
}

// Yet another option if class 'A' was not the object that constructed
an instance of 'B':
public void Initialize(Syst em.Runtime.Refl ection.Assembly caller)
{
if (caller == null)
throw new ArgumentNullExc eption("caller" );

callingAssembly = caller;
}
}
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Theodore" <t@t.t> wrote in message
news:uu******** ******@TK2MSFTN GP10.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
ExecutingAssemb ly 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 GetEntryAssembl y 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
3102
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 v 1.0.3705 to v 1.1.4322 of the framework (and to the 2003 IDE); I've been recompiling old 1.0 components. I had created the assembly and installed in the GAC with a
2
20682
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 applications." Although I have seen this before when trying to remove .NET assemblies that have been installed via an MSI package, I now get this message while trying to remove any assembly I've added to the GAC. Using gacutil does not work...
0
1697
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 specify the interfaces and the data types which flow through the interfaces. Initially, we thought this would be enough for the client to talk with the server. In general it is, but when an exception is generated by the server it fails to...
5
1637
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 imnherits from A. This is the code: Type t = this.GetType(); FieldInfo parameterInfo = t.GetField(field,BindingFlags.Instance |
4
2598
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". I do in fact have a reference to the assembly in question in the project and I even tried declaring it with "using" at the top of the class file. Here's the method that fails:
2
1766
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 I then get this error when I refresh the browser. I have to restart IIS to fix the problem. I've included the error info but it all looks very cryptic to me. How do I find out what's really happening and how to fix it? Thanks
3
4412
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
3965
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 getting the Access denied error. After checking different settings and googling I wasnt able to pinpoint the problem and as a temporary fix I decided to merge the two assemblies into one, my logic being no offending assembly no access denied...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10083
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
9946
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
7494
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
5379
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.