C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Types of Assemblies , Creating a Private Assembly ,Probing


Posted Date: 12 Jun 2006    Resource Type: Articles    Category: .NET Framework
Author: HimaBindu VeeramachaneniMember Level: Diamond    
Rating: Points: 10



Types of Assemblies


As Assemblies are buliding blocks of Dotnet Frame work there are 3 types of Assemblies
1. Private
2. Shared
3. Satellite

Private AssemblyThe Assembly that is local to the particular folder is called Private Assembly
The disadvantage is that each time a copy of the Assembly is created which in turn occupies more memory and reduces the performance

Shared AssemblyWhen we maintain one copy of the Assembly for set of applications through out the system it is called Shared Assembly
More memory usage can be reduced by this concept

So here comes the concept of public key and version number to maintain unique ness of the Assembly for particular application.

Satellite AssemblyWhen you wish to make the application customizable for different languages and cultures and distribute the localized modules in separate assemblies called satellite assemblies.
It can be written in code that uses resources from an assembly rather than hard-coding the resources in the program

Private Assembly


When we compile the C# Program Console Application an exe will be created

To Create dll from the Command Prompt


Open Note pad and Type the Following
Example:
namespace MyApp
{
public class MathC
{
private int a,b;
private int res;
public void Accept( int A,int B)
{
a =A;
b= B;
}
public int Sum()
{
res = a+b;
return res;
}
}
}

Save it as Mydll.cs

Compilation : csc /t:library Mydll.cs

Mydll.dll is Produced


Calling this assembly in Client Application


using System;
using MyApp;

class C{
static void Main()
{
MathC obj = new MathC();
obj.Accept(10,20);
Console.WriteLine("Obj value is"+obj.Sum());
}
}

Save it as ClientApp.cs

If we compile csc ClientApp.cs it gives error

The correct compilation is csc /r: mydll.dll ClientApp.cs

/r refers to reference switch.
It’s a request to the complier to verify name spaces (all) with in System.dll by default. When we want to provide a custom library to verify the namespace then we require reference switch option

Hence this will produce ClientApp.exe
And the result is executed

C:\>ClientApp
Obj value is30

C:\>md Dir1

C:\>copy PAssembly.dll Dir1
1 file(s) copied.

C:\>del PAssembly.dll

C:\>ClientApp

LOG: Attempting download of new URL file:///C:/PAssembly.DLL.
LOG: Attempting download of new URL file:///C:/PAssembly/PAssembly.DLL.
LOG: Attempting download of new URL file:///C:/PAssembly.EXE.
LOG: Attempting download of new URL file:///C:/PAssembly/PAssembly.EXE.

Run Time will search for Mydll.dll in C Drive
And gives the Error Message

Probing


Probing can be defined as Runtime Searching for the Assembly required to the Application
When it comes to private assembly Runtime will search for Application Folder and subfolder with in a library name for the particular assembly
When we want to extend probing with other directories then provide the information to the runtime in a special file called Configuration file

Save it as ClientApp.exe.Config


<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<probing privatePath="Dir1"/>

</assemblyBinding>

</runtime>
</configuration>



assemblyBinding Contains information about assembly version redirection and the locations of assemblies.
configuration The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime Contains information about assembly binding and garbage collection.

Now go to VS Command Prompt and just run ClientApp
Then It will search for the Assembly in the Located path as Dir1 in the Specific Root Directory and all the Subfolders

We get the output as : Sum is 30

Built in Library vs Custom Library


Built in Library defined by the MS comes from System NameSpace
Console Class

Custom Library defined by the Developer that is Mydll
MathC is the class
Import the name space with ‘using’ keyword






Responses

Author: Anuj Rathi    28 Jul 2006Member Level: Gold   Points : 0
hi Hima mam,
As u told that assemblies are of three types, Private, Public & Satellite.

But I think these are of only two types:
1. Single File &
2. Multi File assemblies.
Now you can say that the scope of assemblies are of three types.
1. Private
2. Public and
3. satellite
Am I right ? I am also confusing about this. So pls if you feel that i am right, then pls also inform me.

Regards,
Anuj Kumar


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Assemblies
Previous Resource: Shared Assemblies
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use