By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,462 Members | 3,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,462 IT Pros & Developers. It's quick & easy.

Referencing a multifile assembly

P: n/a
I'm having trouble doing someting apparently simple. I'm still not very
familiar with Visual Studio 2003, so apologies if I've missed something
obvious.

Basically my problem is the following. I have 2 files that contain each
one a very simple class. I compiled them as .netmodules. Both classes
are under the same namespace.

I then bundled these .netmodules files into a dll. This gives me an
assembly of 3 files which was confirmed by the manifest.

Now I create a new project and add a reference to the dll I just
created. This has the effect of copying the 3 files in a directory in my
debug directory. So far so good. I then use a using directive for the
namespace in which both classes are.

Problem is I stil can't access these classes from my new project. Double
clicking on the reference from the Solution Explorer sends me to the
object browser where I can see that there is something wrong with the
reference as I can't see the namespace there. It's in fact empty. So I
probably missed a step somewhere, but where?

Thanks for your help.
Nov 16 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Hi Pollux,

I will assume from what you write. Please correct me if i am wrong.

Just say:

You had using 1 large namespace called ParentProject

You had 2 sub namespaces within ParentProject - ParentProject.AppA and ParentProject.AppB

So the hierarchy

ParentProject // a blank solution
--> ParentProject.AppA // C# class library project
----> Car.cs
--> ParentProject.AppB // C# class library project
----> Motor.cs
--> Tester // C# Windows App Test Program

Inside your Tester,

you will add references to ParentProject.AppA and ParentProject.AppB

then inside your C# Test Form1.cs

you add this:

using ParentProject.AppA;
using ParentProject.AppB;
// never expect this okay, as below:
// using ParentProject.AppA.Car; // never will work here.

....

when you want to call the Car

Car carValue = new Car(); // It works here.. not at the directives.

Same to the others.

Hope it helps you a bit. Hope you get the right concept. Good Luck.
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
I'm having trouble doing someting apparently simple. I'm still not very
familiar with Visual Studio 2003, so apologies if I've missed something
obvious.

Basically my problem is the following. I have 2 files that contain each
one a very simple class. I compiled them as .netmodules. Both classes
are under the same namespace.

I then bundled these .netmodules files into a dll. This gives me an
assembly of 3 files which was confirmed by the manifest.

Now I create a new project and add a reference to the dll I just
created. This has the effect of copying the 3 files in a directory in my
debug directory. So far so good. I then use a using directive for the
namespace in which both classes are.

Problem is I stil can't access these classes from my new project. Double
clicking on the reference from the Solution Explorer sends me to the
object browser where I can see that there is something wrong with the
reference as I can't see the namespace there. It's in fact empty. So I
probably missed a step somewhere, but where?

Thanks for your help.

Nov 16 '05 #2

P: n/a
Hi pollux again,

What is *.netmodules? Mind to share it. I never seen it before.

Thanks.
--
Regards,
Chua Wen Ching :)
"Chua Wen Ching" wrote:
Hi Pollux,

I will assume from what you write. Please correct me if i am wrong.

Just say:

You had using 1 large namespace called ParentProject

You had 2 sub namespaces within ParentProject - ParentProject.AppA and ParentProject.AppB

So the hierarchy

ParentProject // a blank solution
--> ParentProject.AppA // C# class library project
----> Car.cs
--> ParentProject.AppB // C# class library project
----> Motor.cs
--> Tester // C# Windows App Test Program

Inside your Tester,

you will add references to ParentProject.AppA and ParentProject.AppB

then inside your C# Test Form1.cs

you add this:

using ParentProject.AppA;
using ParentProject.AppB;
// never expect this okay, as below:
// using ParentProject.AppA.Car; // never will work here.

...

when you want to call the Car

Car carValue = new Car(); // It works here.. not at the directives.

Same to the others.

Hope it helps you a bit. Hope you get the right concept. Good Luck.
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
I'm having trouble doing someting apparently simple. I'm still not very
familiar with Visual Studio 2003, so apologies if I've missed something
obvious.

Basically my problem is the following. I have 2 files that contain each
one a very simple class. I compiled them as .netmodules. Both classes
are under the same namespace.

I then bundled these .netmodules files into a dll. This gives me an
assembly of 3 files which was confirmed by the manifest.

Now I create a new project and add a reference to the dll I just
created. This has the effect of copying the 3 files in a directory in my
debug directory. So far so good. I then use a using directive for the
namespace in which both classes are.

Problem is I stil can't access these classes from my new project. Double
clicking on the reference from the Solution Explorer sends me to the
object browser where I can see that there is something wrong with the
reference as I can't see the namespace there. It's in fact empty. So I
probably missed a step somewhere, but where?

Thanks for your help.

Nov 16 '05 #3

P: n/a
In article <C5**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi pollux again,

What is *.netmodules? Mind to share it. I never seen it before.

Thanks.


I'm new to .Net, but if you're familiar with Win32 programming, the
closest thing that comes to mind is a .lib file or a statically linked
library. I think the proper name is Class library.
Nov 16 '05 #4

P: n/a
In article <41**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

I will assume from what you write. Please correct me if i am wrong.

Just say:

You had using 1 large namespace called ParentProject

You had 2 sub namespaces within ParentProject - ParentProject.AppA and ParentProject.AppB

So the hierarchy

ParentProject // a blank solution
--> ParentProject.AppA // C# class library project
----> Car.cs
--> ParentProject.AppB // C# class library project
----> Motor.cs
--> Tester // C# Windows App Test Program

Inside your Tester,

you will add references to ParentProject.AppA and ParentProject.AppB

then inside your C# Test Form1.cs

you add this:

using ParentProject.AppA;
using ParentProject.AppB;
// never expect this okay, as below:
// using ParentProject.AppA.Car; // never will work here.

...

when you want to call the Car

Car carValue = new Car(); // It works here.. not at the directives.

Same to the others.

Hope it helps you a bit. Hope you get the right concept. Good Luck.


I guess I was my example was a bit confusing.

Basically I have the following:
2 files: MathLib.cs, StringLib.cs

Each file contains one class. Each class uses Namespace StepByStep4_13

It's supposed to be an example on using multifile assemblies so you
can't use VS to do that. I use the command line to generate a dll out of
the two files. This gives me an assembly with three files.

I now create a Tester program in order to use these two classes. I add a
reference to the dll directly which adds the three files to the project
as expected. I also add a using StepByStep4_13 directive although this
doesn't really have any influence on the reference. Still, it doesn't
work. It looks like I missed a step somewhere.
Nov 16 '05 #5

P: n/a
Hi Pollux,

You suppose to see something inside the object browser.

This is what i will do, a very basic sample.

ParentProject
----------------
Animal.cs:

using System;

namespace ParentProject
{
public class Animal
{
public Animal()
{

}
public int calc(int a, int b)
{
return a + b;
}
}
}

Car.cs:

using System;

namespace ParentProject
{
public class Car
{
public Car()
{

}
public void showmessage()
{
Console.WriteLine("Hello World");
}
}
}

Compiles:

csc /target:library /out:Parent.dll Animal.cs Car.cs

will generate a class library Parent.dll

Then, you open a new tester program. Add references to Project.dll

code this in test Form1.cs:

using ParentProject; // not Parent

....

int testInteger;
// to access Animal class's function
Animal aVar = new Animal();
testInteger = aVar.calc(1, 2);

// to access Car class's function
Car bVar = new Car();
bVar.showmessage();

In your object browser, this is what you will see:

- Parent
- - {} ParentProject
- - - Animal
- - - - Bases and Interfaces
- - - - Object
- - - Car
- - - - Bases and Interfaces
- - - - Object

Hope this helps again. This is a beginner sample. Correct me if i am wrong. :)
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <41**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

I will assume from what you write. Please correct me if i am wrong.

Just say:

You had using 1 large namespace called ParentProject

You had 2 sub namespaces within ParentProject - ParentProject.AppA and ParentProject.AppB

So the hierarchy

ParentProject // a blank solution
--> ParentProject.AppA // C# class library project
----> Car.cs
--> ParentProject.AppB // C# class library project
----> Motor.cs
--> Tester // C# Windows App Test Program

Inside your Tester,

you will add references to ParentProject.AppA and ParentProject.AppB

then inside your C# Test Form1.cs

you add this:

using ParentProject.AppA;
using ParentProject.AppB;
// never expect this okay, as below:
// using ParentProject.AppA.Car; // never will work here.

...

when you want to call the Car

Car carValue = new Car(); // It works here.. not at the directives.

Same to the others.

Hope it helps you a bit. Hope you get the right concept. Good Luck.


I guess I was my example was a bit confusing.

Basically I have the following:
2 files: MathLib.cs, StringLib.cs

Each file contains one class. Each class uses Namespace StepByStep4_13

It's supposed to be an example on using multifile assemblies so you
can't use VS to do that. I use the command line to generate a dll out of
the two files. This gives me an assembly with three files.

I now create a Tester program in order to use these two classes. I add a
reference to the dll directly which adds the three files to the project
as expected. I also add a using StepByStep4_13 directive although this
doesn't really have any influence on the reference. Still, it doesn't
work. It looks like I missed a step somewhere.

Nov 16 '05 #6

P: n/a
In article <C1**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

You suppose to see something inside the object browser.

This is what i will do, a very basic sample.

ParentProject
----------------
Animal.cs:

using System;

namespace ParentProject
{
public class Animal
{
public Animal()
{

}
public int calc(int a, int b)
{
return a + b;
}
}
}

Car.cs:

using System;

namespace ParentProject
{
public class Car
{
public Car()
{

}
public void showmessage()
{
Console.WriteLine("Hello World");
}
}
}

Compiles:

csc /target:library /out:Parent.dll Animal.cs Car.cs


Hi Chua,

there is a fundamental difference between our code. Your Parent.dll file
is a single file assembly whereas mine would be composed of:

Parent.dll car.netomodule and animal.netmodule

In the object browser, I only see a Parent, but nothing underneath it.
Nov 16 '05 #7

P: n/a
Hi Pollux,

Okay, i am mix up. I didn't know you meant multifile. Oops.. i am confuse with the term.

I seldom use multifile assembly. But from what i see:

Do this:

Namespace: ParentObject

Animal.cs
------------
csc /t:module Animal.cs

Car.cs
---------
csc /t:module Car.cs

Your Console App / Windows App (when you compile windows app, you need to reference system.windows. form)

csc /addmodule:Animal.netmodule /addmodule:Car.netmodule /t:module Tester.cs

Then

csc /out:Tester.exe Tester.cs /out:Animal.netmodule Animal.cs /out:Car.netmodule Car.cs

If you do that, it will work. But again, i had tried the dll thing and again import into a new vs.net project, i can't see anything like you. I doubt it will work. Correct me if i am wrong.

I hope someone who have more experience in multifile can help you.

Cheers.

--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <C1**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

You suppose to see something inside the object browser.

This is what i will do, a very basic sample.

ParentProject
----------------
Animal.cs:

using System;

namespace ParentProject
{
public class Animal
{
public Animal()
{

}
public int calc(int a, int b)
{
return a + b;
}
}
}

Car.cs:

using System;

namespace ParentProject
{
public class Car
{
public Car()
{

}
public void showmessage()
{
Console.WriteLine("Hello World");
}
}
}

Compiles:

csc /target:library /out:Parent.dll Animal.cs Car.cs


Hi Chua,

there is a fundamental difference between our code. Your Parent.dll file
is a single file assembly whereas mine would be composed of:

Parent.dll car.netomodule and animal.netmodule

In the object browser, I only see a Parent, but nothing underneath it.

Nov 16 '05 #8

P: n/a
In article <83**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

Okay, i am mix up. I didn't know you meant multifile. Oops.. i am confuse with the term.

I seldom use multifile assembly. But from what i see:

Do this:

Namespace: ParentObject

Animal.cs
------------
csc /t:module Animal.cs

Car.cs
---------
csc /t:module Car.cs

Your Console App / Windows App (when you compile windows app, you need to reference system.windows. form)

csc /addmodule:Animal.netmodule /addmodule:Car.netmodule /t:module Tester.cs

Then

csc /out:Tester.exe Tester.cs /out:Animal.netmodule Animal.cs /out:Car.netmodule Car.cs

If you do that, it will work. But again, i had tried the dll thing and again import into a new vs.net project, i can't see anything like you. I doubt it will work. Correct me if i am wrong.

I hope someone who have more experience in multifile can help you.

Cheers.


I have no idea why, but when I shut down VS and restarted it it
magically worked and didn't complain about the missing reference.
Nov 16 '05 #9

P: n/a
Hi Pollux,

After trial and error. I had finalized the right steps to do a multifile assembly. I notice very funny and weird problems. But i write as detail as possible so you can follow up.

Before we delve into coding, the hierarchy of the project:

ParentProject Namespace (to achieve parent.dll)
--> animal.cs
--> human.cs

Codes:

animal.cs
------------
using System;

namespace ParentProject
{
class Animal
{
public void SearchForAnimal()
{
Console.WriteLine("This is lion");
}
}
}

When you had code finish animal.cs, compile it with:

csc.exe /t:module animal.cs

it will generates animal.netmodule.

Codes:

human.cs
------------
using System;

namespace ParentProject
{
public class Human
{
public void MeasureHeight()
{
Console.WriteLine("Height is 180cm");
}
}
}

Now you had to generate the parent.dll.

csc.exe /t:library /addmodule:animal.netmodule /out:parent.dll human.cs

this will generate the parent.dll

Now, before we try to code.

Open ildasm.exe, and open the animal.netmodule. Must open, not sure why. Double click the manifest.

Manifest
-----------
..assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.hash = (E6 8E F4 00 2B 3C 3C 88 D6 32 F2 72 A3 22 FA C8 // ....+<<..2.r."..
A7 7B 24 07 ) // .{$.
.ver 1:0:5000:0
}
..module animal.netmodule
// MVID: {E5472D97-AD87-40E5-A136-DCDA3A694B05}
..imagebase 0x00400000
..subsystem 0x00000003
..file alignment 512
..corflags 0x00000001
// Image base: 0x06c40000

Once you are done, now use ildasm.exe to open parent.dll. Double click on Manifest again. Make sure you see this:

Manifest
-----------
..assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.hash = (E6 8E F4 00 2B 3C 3C 88 D6 32 F2 72 A3 22 FA C8 // ....+<<..2.r."..
A7 7B 24 07 ) // .{$.
.ver 1:0:5000:0
}
..assembly parent
{
// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool ,
// bool) = ( 01 00 00 01 00 00 )
.hash algorithm 0x00008004
.ver 0:0:0:0
}
..file animal.netmodule
.hash = (56 A3 83 2D FA A2 4C 4E 75 B5 21 2F CA 55 29 66 // V..-..LNu.!/.U)f
22 A3 19 64 ) // "..d
..module parent.dll
// MVID: {FF4E133B-DB7D-41BD-983B-8B08AB9C4265}
..imagebase 0x00400000
..subsystem 0x00000003
..file alignment 512
..corflags 0x00000001
// Image base: 0x06c40000

Now, open a new console project. Add references to parent.dll.

Double click on parent.dll to open the Object Browser, you can see this:

- parent
- - {} ParentProject
- - - Human
- - - Bases and Interfaces
- - - - Object

Don't worry if you can't see Animal class. It is quite normal as Animal is a submodule of Human class.

Okay, time for testing.

Codes:

Tester.cs
-----------
using System;
using ParentProject;

namespace Tester
{
public class Tester
{
public static void Main()
{
Animal aVar = new Animal();
aVar.SearchForAnimal();

Human bVar = new Human();
bVar.MeasureHeight();
}
}
}

Start without debugging if you have vs.net.

or use:

csc.exe /out:Tester.exe Tester.cs

You will see the output.

That is all. Hope this can help you even more. Not sure how you solve it by restarting, suprise to hear that.

Hope it helps. Cheers.
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <83**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

Okay, i am mix up. I didn't know you meant multifile. Oops.. i am confuse with the term.

I seldom use multifile assembly. But from what i see:

Do this:

Namespace: ParentObject

Animal.cs
------------
csc /t:module Animal.cs

Car.cs
---------
csc /t:module Car.cs

Your Console App / Windows App (when you compile windows app, you need to reference system.windows. form)

csc /addmodule:Animal.netmodule /addmodule:Car.netmodule /t:module Tester.cs

Then

csc /out:Tester.exe Tester.cs /out:Animal.netmodule Animal.cs /out:Car.netmodule Car.cs

If you do that, it will work. But again, i had tried the dll thing and again import into a new vs.net project, i can't see anything like you. I doubt it will work. Correct me if i am wrong.

I hope someone who have more experience in multifile can help you.

Cheers.


I have no idea why, but when I shut down VS and restarted it it
magically worked and didn't complain about the missing reference.

Nov 16 '05 #10

P: n/a
In article <13**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

After trial and error. I had finalized the right steps to do a multifile assembly. I notice very funny and weird problems. But i write as detail as possible so you can follow up.

Before we delve into coding, the hierarchy of the project:

ParentProject Namespace (to achieve parent.dll)
--> animal.cs
--> human.cs

Codes:

animal.cs
------------
using System;

namespace ParentProject
{
class Animal
{
public void SearchForAnimal()
{
Console.WriteLine("This is lion");
}
}
}

When you had code finish animal.cs, compile it with:

csc.exe /t:module animal.cs

it will generates animal.netmodule.

Codes:

human.cs
------------
using System;

namespace ParentProject
{
public class Human
{
public void MeasureHeight()
{
Console.WriteLine("Height is 180cm");
}
}
}


Ok, I haven't been able to reproduce the problem that prevented me from
compiling, but I see what we're doing differenly and why we're seeing
different results. I compiled both files separately and then created an
assembly through the dll.

csc /t:module animal.cs
csc /t:module human.cs
csc /t:library /out:parent.dll
/addmodules:animal.netmodules,human.netmodules

If you do ildasm utils.dll, you'll only see the manifest. In the object
browser you won't see anything. I guess this is normal, it's just the
way Visual Studio handles multi files assemblies. Also, if you use the
class in VS, you won't get any intellisense for it, ie you won't get any
tooltips giving you its methods.
Nov 16 '05 #11

P: n/a
Hi Pollux,

Yeah i did try that way. You get couple of netmodules right? But it doesn't work in my computer. The parent.dll seems to be not working. I can't call Animal or Human class at all.

Well i able to get intellisense to work now with the solution i provided earlier.

When i type

Animal aVar = new (intellisense popup and point on Animal) Animal();
aVar.(intellisense popup, and i selected showmessage)showmessage();

For tooltips, I am not that sure, but I think if you add xml comments, it will appear.

Thanks for replying back. :) So is everything okay.
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <13**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

After trial and error. I had finalized the right steps to do a multifile assembly. I notice very funny and weird problems. But i write as detail as possible so you can follow up.

Before we delve into coding, the hierarchy of the project:

ParentProject Namespace (to achieve parent.dll)
--> animal.cs
--> human.cs

Codes:

animal.cs
------------
using System;

namespace ParentProject
{
class Animal
{
public void SearchForAnimal()
{
Console.WriteLine("This is lion");
}
}
}

When you had code finish animal.cs, compile it with:

csc.exe /t:module animal.cs

it will generates animal.netmodule.

Codes:

human.cs
------------
using System;

namespace ParentProject
{
public class Human
{
public void MeasureHeight()
{
Console.WriteLine("Height is 180cm");
}
}
}


Ok, I haven't been able to reproduce the problem that prevented me from
compiling, but I see what we're doing differenly and why we're seeing
different results. I compiled both files separately and then created an
assembly through the dll.

csc /t:module animal.cs
csc /t:module human.cs
csc /t:library /out:parent.dll
/addmodules:animal.netmodules,human.netmodules

If you do ildasm utils.dll, you'll only see the manifest. In the object
browser you won't see anything. I guess this is normal, it's just the
way Visual Studio handles multi files assemblies. Also, if you use the
class in VS, you won't get any intellisense for it, ie you won't get any
tooltips giving you its methods.

Nov 16 '05 #12

P: n/a
In article <59**********************************@microsoft.co m>,
ch************@nospam.hotmail.com says...
Hi Pollux,

Yeah i did try that way. You get couple of netmodules right? But it doesn't work in my computer. The parent.dll seems to be not working. I can't call Animal or Human class at all.

Well i able to get intellisense to work now with the solution i provided earlier.

When i type

Animal aVar = new (intellisense popup and point on Animal) Animal();
aVar.(intellisense popup, and i selected showmessage)showmessage();

For tooltips, I am not that sure, but I think if you add xml comments, it will appear.

Thanks for replying back. :) So is everything okay.


Yep as I said, since I restarted Visual Studio, I haven't been able to
reproduce the problem. I'm not seeing the intellisense in VS though. Oh
well, time to move on to Data Bindings.
Nov 16 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.