How to share data between assemblies?

B

Bill McCormick

What is the correct (simplest) way to share data between assemblies?

In very simple, generic terms - for the purpose of illustration, lets
say we have the following:

//Assembly 1
using Assembly2;

namespace Assembly1 {
class class1 {
public string someData;
...
}
}

//Assembly 2
namespace Assembly2 {
class class2 {
public string someMethod() {
//should return Assembly1.class1.someData;
}
}
}

What I'm trying to accomplish is to have a WCF service (someMethod)
located in Assembly2 return someData located in Assembly1.

Thanks,

Bill
 
B

Bill McCormick

Peter said:
Strictly speaking, you don't. You share data between classes. And you
do it the same way whether the classes are in the same assembly or not:
one class has to have a reference to the other and some way to pass data
to it or get data from it, such as a method or property in the other class.

It's possible that instead of asking "how to share data", what you
really want to know is "how to have two assemblies reference each
other". If that's the case, you may find this recent thread useful:
http://groups.google.com/group/micr....csharp/browse_thread/thread/6a6c6dc307287c01


Pete
What I ended up doing was moving the code from Assembly2 to Assembly1;
now Assembly2 is just gone and so is the issue.

Thanks,

Bill
 
B

Bill McCormick

Peter said:
Strictly speaking, you don't. You share data between classes. And you
do it the same way whether the classes are in the same assembly or not:
one class has to have a reference to the other and some way to pass data
to it or get data from it, such as a method or property in the other class.

It's possible that instead of asking "how to share data", what you
really want to know is "how to have two assemblies reference each
other". If that's the case, you may find this recent thread useful:
http://groups.google.com/group/micr....csharp/browse_thread/thread/6a6c6dc307287c01


Pete
What I ended up doing was moving the code from Assembly2 to Assembly1;
now Assembly2 is just gone and so is the issue.

Thanks,

Bill
 
B

Bill McCormick

Peter said:
Strictly speaking, you don't. You share data between classes. And you
do it the same way whether the classes are in the same assembly or not:
one class has to have a reference to the other and some way to pass data
to it or get data from it, such as a method or property in the other class.

It's possible that instead of asking "how to share data", what you
really want to know is "how to have two assemblies reference each
other". If that's the case, you may find this recent thread useful:
http://groups.google.com/group/micr....csharp/browse_thread/thread/6a6c6dc307287c01


Pete
What I ended up doing was moving the code from Assembly2 to Assembly1;
now Assembly2 is just gone and so is the issue.

Thanks,

Bill
 
J

J.B. Moreno

Bill McCormick said:
-snip-
What I ended up doing was moving the code from Assembly2 to Assembly1;
now Assembly2 is just gone and so is the issue.

If that was *all* you did, then all you it would have been simpler to
reference the project/dll for assembly 2 from the project for
Assembly1.

(Not that I'm saying ending up with one file was a bad idea, in fact I
generally lean that way myself. Just some thing to keep in mind the
next time).
 

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