473,395 Members | 1,335 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,395 software developers and data experts.

sharing objects between .net applications

I need to reuse the object from one .net application in another .net
application. So far I was able to do it as long as both .exe files were in
the same folder. How can I place them in different folders and make sure
that one application finds another at runtime?
Jul 15 '08 #1
7 1362
Do you mean you want to reuse code from a dependency library? If so, you can
distribute the library with both of the executables or install it in the GAC
(Global Assembly Cache). That way it will always be found but versioning
might become a slight problem.

Search for "assemblies GAC" and you should be able to find the necessary
information.

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info

"Gregory Khra" <Gr*********@discussions.microsoft.comwrote in message
news:3C**********************************@microsof t.com...
>I need to reuse the object from one .net application in another .net
application. So far I was able to do it as long as both .exe files were in
the same folder. How can I place them in different folders and make sure
that one application finds another at runtime?
Jul 15 '08 #2
"Stanimir Stoyanov" wrote:
Do you mean you want to reuse code from a dependency library?
No, this is exactly what I am trying to avoid. It would be difficult to
extract necessary objects from the main application into an independant DLL.
I just want to reuse one class from the main application in a different app.
with minimum work. I don't want to install the main app to GAC (I am not
even sure I can install .exe to GAC). Is there a way to tell auxiliary app
where the main app is?
Jul 15 '08 #3
You can add a shortcut to your .cs file in another project from Project->Add
Existing Item... and make sure to select Add As Link. Changes to the code
will reflect in both projects. Note that you might have to add other classes
in the same fashion in case the first one references them.

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info

"Gregory Khra" <Gr*********@discussions.microsoft.comwrote in message
news:A3**********************************@microsof t.com...
"Stanimir Stoyanov" wrote:
>Do you mean you want to reuse code from a dependency library?

No, this is exactly what I am trying to avoid. It would be difficult to
extract necessary objects from the main application into an independant
DLL.
I just want to reuse one class from the main application in a different
app.
with minimum work. I don't want to install the main app to GAC (I am not
even sure I can install .exe to GAC). Is there a way to tell auxiliary app
where the main app is?
Jul 15 '08 #4
You can add a shortcut to your .cs file in another project from Project->Add
Existing Item... and make sure to select Add As Link.
Unfortunately this .cs file uses objects that are defined in the other .cs
files which are using other objects ... etc. As I said, it is difficult to
extract the object I need from its environment (I realize that it's bad
design, but it's too late to change).

So far I was able to create a reference in my Visual Studio project and just
reuse the namespace from another application. The problem is that it only
works if at runtime both exe files are in the same folder.
Jul 15 '08 #5
I see. To answer your question a post above "Is there a way to tell
auxiliary app
where the main app is?", I do not know what kind of mapping your application
is using but it *might* be possible to achieve this by changing the current
directory of the execution context at application startup, preferably as the
first call in your Program class:

Environment.CurrentDirectory = @"C:\my\path";

You still have to be able to determine what the path should be.

Best Regards,
Stanimir Stoyanov
www.stoyanoff.info

"Gregory Khra" <Gr*********@discussions.microsoft.comwrote in message
news:34**********************************@microsof t.com...
>You can add a shortcut to your .cs file in another project from
Project->Add
Existing Item... and make sure to select Add As Link.

Unfortunately this .cs file uses objects that are defined in the other .cs
files which are using other objects ... etc. As I said, it is difficult to
extract the object I need from its environment (I realize that it's bad
design, but it's too late to change).

So far I was able to create a reference in my Visual Studio project and
just
reuse the namespace from another application. The problem is that it only
works if at runtime both exe files are in the same folder.

Jul 15 '08 #6
Environment.CurrentDirectory = @"C:\my\path";

I tried it. Doesn't work. Now I am playing with app.config but cannot find
the appropriate syntax. I was hoping someone can give me an example.
Gregory
Jul 15 '08 #7
On Tue, 15 Jul 2008 20:08:02 +0200, Gregory Khra
<Gr*********@discussions.microsoft.comwrote:
>Environment.CurrentDirectory = @"C:\my\path";

I tried it. Doesn't work. Now I am playing with app.config but cannot
find
the appropriate syntax. I was hoping someone can give me an example.
Gregory
The app.config has an element where you can tell the runtime environment
where to look for assemblies. However, the paths that you add here can
only be "private" - ie. subdirectories to the installation dir of the
client app. More info on this option here:
http://msdn.microsoft.com/en-us/library/823z9h8w.aspx

If this does not work for you (from what you have told I guess it does
not), I believe that your only option is to do an explicit call to the
Assembly.LoadFrom() method, documented here:
http://msdn.microsoft.com/en-us/libr....loadfrom.aspx
--
Joern Schou-Rode
http://malamute.dk/
Jul 20 '08 #8

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

Similar topics

3
by: Jose Munoz | last post by:
Hi all, I want to share some data for all my applications (servlets and jsps). For this i am using a JSP to set the variables with scope=application. When i get this data from some JSP all is o.k,...
1
by: baylor | last post by:
Are there are any best practices or guidance on how to share an object between the Web world and the non? Here's my situation: i have one object (a security profile containing IPrincipal + some...
6
by: varlagas | last post by:
We disabled the antivirus software but the problem persists. Any clues? Many thanks in advance! Panagiotis Varlagas ======================================================================= ...
6
by: Sajid Saeed | last post by:
Hi All, I wuld like to know if there is any possibility of sharing a common class between different applications. i.e. if the two applications are running, they can share the class, and changes...
5
by: BPearson | last post by:
Hello I would like to have several sites share a single web.config file. To accomplish this, I would point the root of these sites to the same folder. Is there any reason why I might not want to...
3
by: grooby | last post by:
I would like to develop an asp.net Web application using muliple web projects under one solution file and share the session information between web applications( or projects). Is this possible?
4
by: qube3 | last post by:
We have applications written by JSP/Servlet and ASP.NET. All our future development would be based on ASP.NET. We wants to develop a single user interface so that users would not be aware that...
4
by: abcd | last post by:
I have an ASP application. It instantiaties some COM components and we put those COM components in Session variables...COM components have license restrictions...We have written new ASPX page ( for...
2
by: Michael Isaacs | last post by:
Is there any way to share an object or variable between applications other than through .NET remoting? Also, if this is the only way, what kind of overhead is there for storage (memory) and speed...
8
by: antonyliu2002 | last post by:
We are extending a web application written in classic ASP long time ago. We will add more components to this web application in ASP.NET 2.0. To use the web application, our web users will have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.