An Assembly can include several .exe files?

  • Thread starter Thread starter Guest
  • Start date Start date
Nice,

No, it can't. It can include several modules, but not several EXE
files. After all, it's one file, which can be of type exe or DLL.

Hope this helps.
 
Nicholas Paldino said:
Nice,

No, it can't. It can include several modules, but not several EXE
files. After all, it's one file, which can be of type exe or DLL.

Hope this helps.

An assembly can contain many files. As far as I know, only one of them can
be of type .DLL or .EXE. And I'm not sure if it's required that there be
either an EXE or DLL: can any other type of file contain the assembly
manifest?
 
Mike,

An assembly can contain many modules. Ultimately though, an assembly is
ONE file, with ONE manifest.

A module is not an EXE or a DLL, it is a module, very different.

Big difference.
 
Nicholas Paldino said:
Mike,

An assembly can contain many modules. Ultimately though, an assembly
is ONE file, with ONE manifest.

No, that's not true. (Well, the one manifest part is true.)

See, for instance, http://www.dnzone.com/ShowDetail.asp?NewsId=698, which
says

What is an assembly?
* An Assembly is a logical unit of code
* One assembly can contain one or more files :

There is one *main* file in as assembly, the one that contains the assembly
manifest. But it can refer to an arbitrary number of other files, all of
which are part of the assembly. To see this, do the following:

Link some C# classes into a module. It doesn't really matter what's in
them.

Link the following class into an executable, adding in the module created in
the previous step: (The command line looks like
"csc /addmodule:Package.netmodule Hello.cs" )

using System;
using System.IO;
using System.Reflection;

class Hello {
public static void Main()
{
try {
Assembly assm = Assembly.GetAssembly(typeof(Hello));
FileStream[] files = assm.GetFiles();
Console.WriteLine("" + files.Length + " files in assembly");
foreach (FileStream f in files) {
Console.WriteLine(f.Name);
}
}
catch (Exception ex) {
Console.WriteLine(ex);
}
}
}

Run it. You'll see output like:

2 files in assembly
c:\csharp\Hello.exe
c:\csharp\package.netmodule

Now delete the file containing the module. Try to run the executable again,
and you'll see an error like:
System.IO.FileNotFoundException: File or assembly name Package.netmodule,
or one
of its dependencies, was not found.
File name: "Package.netmodule"
at System.Reflection.Assembly.nGetModules(Boolean loadIfNotFound,
Boolean getResourceModules)
at System.Reflection.Assembly.GetFiles(Boolean getResourceModules)
at System.Reflection.Assembly.GetFiles()
at Hello.Main()

The error being that one of the assembly's files is missing.
 
Nicholas Paldino said:
Mike,

An assembly can contain many modules. Ultimately though, an assembly
is ONE file, with ONE manifest.

A module is not an EXE or a DLL, it is a module, very different.

Big difference.


Nick,
Mike is right.

An assembly can span multiple modules AND multiple files, the file is just a
container for a module or a number of modules, the extention DLL or EXE is a
non issue here, you can take anything you like as an extention even for the
main assembly file.

Try this:
// m1.cs
using System;
class Tester
{
static void Main()
{
C c = new C();
c.Run();
}
}

// m2.cs
using System;
public class C
{
public void Run()
{
Console.WriteLine("Hello from m2");
}
}

//build m2 an create output module m2.dll
csc /t:module /out:m2.dll m2.cs
// add m2 to assembly
csc /addmodule:m2.dll m1.cs

Now you have a multifile assembly consisting of m1.exe and m2.dll. m1
contains the assembly manifest for m1 and m2.

Note that you can even do this :
csc /addmodule:m2.dll /out:m1.whatever m1.cs
and run it as m1.whatever

Willy.
 
Back
Top