1 Namespaces and Assemblies © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Using.NET Platform Note: Most of the material of these slides have been taken & extended from Nakov’s excellent overview for.NET framework, MSDN and wikipedia.
1 CIS224 Software Projects: Software Engineering and Research Methods Lecture 9 Object, Package, Component and Deployment Diagrams (Based on Fowler, 2004,
Building Localized Applications with Microsoft.NET Framework and Visual Studio.NET Achim Ruopp International Program Manager Microsoft Corp.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
PACKAGES. PACKAGES IN JAVA A package is a collection of related classes and interfaces in Java Packages help in logical grouping of classes and interfaces.
Programming with Objects: Class Libraries and Reusable Code.
Deployment Your Salvation from DLL Hell. Objectives Overview Assemblies „XCopy“ Deployment Configuration Administration.
Advanced Object-Oriented Programming Features
.NET deployment and configuration (but mostly about security) Jørgen Thyme Microsoft Denmark.
.NET Framework Tools Albrecht Wöß Institute for System Software Johannes Kepler University Linz © University of Linz, Institute for System Software, 2004.
Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.
Assembly Where it all gets physical. Objectives Introduce concepts of assemblies Discuss elements of assemblies Show how to build assemblies Runtime aspects.
ASP.Net Security: Fundamentals Chapters 1-4 Freeman and Jones Book.
Views Dwight Deugo Nesa Matic
Introducing the Common Language Runtime. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine.
Tahir Nawaz Visual Programming C# Week 2. What is C#? C# (pronounced "C sharp") is an object- oriented language that is used to build applications for.
Page 1 Sandboxing & Signed Software Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
1 CSE 331 Java Packages; JAR Archives slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
February 24 th -25 th 2004 Daragh Byrne – EPCC Additional.NET Concepts.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
The Metadata System1. 2 Introduction Metadata is data that describes data. Traditionally, metadata has been found in language- specific files (e.g. C/C++
DEV343.NET Application and Library Versioning Juval Löwy
CIS NET Applications1 Chapter 2 –.NET Component- Oriented Programming Essentials.
.NET Framework & C#.
Understanding Code Compilation and Deployment Lesson 4.
Importing outside DLLs into.Net platform and using them By Anupama Atmakur.
SUSE Linux Enterprise Server Administration (Course 3037) Chapter 4 Manage Software for SUSE Linux Enterprise Server.
Implementation Yaodong Bi. Introduction to Implementation Purposes of Implementation – Plan the system integrations required in each iteration – Distribute.
Assemblies & Namespaces1. 2 Assemblies (1).NET applications are represented by an assembly An assembly is a collection of all software of which the application.
ASSEMBLY. A SSEMBLY Assemblies are the fundamental units of applications in the.net framework An assembly can contain classes, structures, interfaces.
ASSEMBLIES AND THE GAC CHAPTER 1, LESSONS 4-7 & LAB.
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Agenda Assemblies 101 Anatomy of an Assembly What is Metadata? Assembly Variations Signing Assemblies Global Assembly Cache.
.NET Framework Danish Sami UG Lead.NetFoundry
Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Java2C# Antonio Cisternino Part V. Outline Assembly & co. Visual Studio environment Example: using DirectX from C#
4/1/05F-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Packages and Components in Java and UML.
.NetDeploymentNOEA / PQC 2005 Application Deployment and Versioning Source: Joe Hummel, kursus i.Net, jan
System.Security.Policy namespace Chinmay Lokesh.NET Security CS 795 Summer 2010.
AUC Technologies Projects Consulting, Development, Mentoring, and Training Company.NET Assemblies Presented By : Muhammad Atif Hussain Deputy Manager IT.
Manage Assemblies. Manage Application Strong Name Create a file: –sn -k a.snk View public key information: –sn -tp a.snk Install file in a CSP Container:
Dissecting the Windows CE Build Process James Y. Wilson Principal Engineer, Windows Embedded MVP CalAmp, Inc. James Y. Wilson Principal Engineer, Windows.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Lecture 4: J# Execution Model. 2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 4-2 Objectives “J# programs execute like any other.NET program.
.NET Ying Chen Junwei Chen. What is Microsoft.NET. NET is a development platform Incorporated into.NET COM+ component services ASP web development framework.
Attributes C#.Net Software Development Version 1.0.
Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke.
Object Oriented Software Development 4. C# data types, objects and references.
Module 4: Deployment and Versioning. Overview Introduction to Application Deployment Application Deployment Scenarios Related Topics and Tools.
July 22, 2001Introduction to.NET1 Introduction to.NET Framework Gholamali Semsarzadeh July 2001.
Text Introduction to.NET Framework. CONFIDENTIAL Agenda .NET Training – Purpose  What is.NET?  Why.NET?  Advantages  Architecture  Components: CLR,
Assemblies. 2 Objectives Introduce assemblies –concept –creation –naming Discuss deployment –main.exe –dependent assemblies.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
OE-NIK HP Advanced Programming Using and creating DLL files.
INF230 Basics in C# Programming
3 Introduction to Classes and Objects.
Chapter 9 S. NandaGopalan, BIT
.NET and .NET Core 2. .NET Runtimes Pan Wuming 2017.
Packages and Interfaces
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
C# Language & .NET Platform 9th Lecture
SPL – PS1 Introduction to C++.
Presentation transcript:

1 Namespaces and Assemblies © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License

2 Namespaces Namespaces are containers for types A file can declare multiple namespaces. A namespace can be re-opened in another file. namespace A {... classes interfaces structs enumerations delegates... } namespace B { // full name: A.B... } namespace C {...}

3 Using Other Namespaces Types declared in a foreign namespace must either be imported (e.g. using Util;) or specified in a qualified name (e.g. Util.Color) namespace Util.Figures { public class Rect {...} public class Circle {...} } namespace Util.Figures { public class Triangle {...} } namespace Util { public enum Color {...} } Color.csFigures.csTriangle.cs using Util.Figures; class Test { Rect r;// without qualification (because of using Util.Figures) Triangle t; Util.Color c;// with qualification }

4 C# Namespaces vs. Java Packages A file may contain multiple namespacesA file may contain just 1 package C#Java namespace A {...} namespace B {...} namespace C {...} xxx.cs package A;... xxx.java Namespaces and classes are not mapped to directories and files Packages and classes are mapped to directories and files namespace A { class C {...} } xxx.cs package A; class C {...} C.java Samples xxx.cs Samples C.java A

5 Namespaces vs. Packages (continued) Imports all public types of a namespaceImports types selectively C#Java using System;import java.util.LinkedList; import java.awt.*; Namespaces are imported in other Namesp.Types are imported in files namespace A { using C;// imports C into A }// only in this file namespace B { using D; } import java.util.LinkedList; Alias names allowed using F = System.Windows.Forms;... F.Button b; for explicit qualification and short names Java has visibility package package A; class C { void f() {...} // package } C# has only visibility internal (!= namespace)

6 Assemblies An assembly is a set of types that are compiled together (+ possibly ressources (icons,...)) a run-time unit stored as a file (*.exe or *.dll) the smallest unit for deployment and dynamic loading the smallest unit for versioning contains code + metadata contains a manifest (i.e. table of contents) similar to a JAR file in Java assemblies are.NET components Manifest Metadata class A class B struct C

7 Namespaces versus Assemblies Namespace compile-time construct controls visibility Assembly run-time construct controls dynamic loading and versioning may contain types from different namespaces namespace X { class A {...} } namespace Y { class B {...} } csc A.cs B.cs file A.cs file B.cs file A.exe contains X.A and Y.B namespace X { class C {...} } file C.cs csc C.cs file C.exe contains X.C

8 How Are Assemblies Created? Every compilation creates either an assembly or a module csc sources A.cs B.cs assembly.exe.dll with manifest module.netmodulewithout manifest Other modules/resources can be added with the assembly linker (al) Difference to Java: Java creates a *.class file for every class executable library modules C.netmodulelibraries D.dll just for resolving references

9 Compiler Options Which output file should be generated? /t[arget]:exeoutput file = console application (default) | winexeoutput file = Windows GUI application | libraryoutput file = library (DLL) | moduleoutput file = module (.netmodule) /doc:namegenerates an XML file with the specified name from /// comments /out:namespecifies the name of the assembly or module default for /t:exename.exe, where name is the name of the source file containing the Main method default for /t:libraryname.dll, where name is the name of the first source file Example:csc /t:library /out:MyLib.dll A.cs B.cs C.cs

10 Compiler Options (continued) How should libraries and modules be embedded? /r[eference]:namemakes metadata in name (e.g. xxx.dll) available in the compilation. name must contain metadata. Example csc /r:MyLib.dll /lib:C:\project A.cs B.cs /addmodule:name {,name}adds the specified modules (e.g. xxx.netmodule) to the generated assembly. But they remain separate files. At run time these modules must be in the same directory as the assembly to which they belong. /lib:dirpath{,dirpath}specifies the directories in which libraries are searched that are referenced by /r.

11 Examples for Compilations csc A.cs=> A.exe csc A.cs B.cs C.cs=> B.exe (if B.cs contains the Main method) csc /out:X.exe A.cs B.cs=> X.exe csc /t:library A.cs=> A.dll csc /t:library A.cs B.cs=> A.dll csc /t:library /out:X.dll A.cs B.cs=> X.dll csc /r:X.dll A.cs B.cs=> A.exe (where A or B reference types in X.dll) csc /addmodule:Y.netmodule A.cs=> A.exe (Y is added to this assembly; but Y.netmodule remains as a separate file)

12 Loading Assemblies at Runtime DLLs are searched in the following directories: in the application directory in all directories that are specified in a configuration file (e.g. MyApp.exe.config) under the tag... in the Global Assembly Cache (for "shared assemblies") A.exe B.dllC.dll Application executable: loaded when invoked from the shell DLLs: loading caused by A.exe

13 Versioning of Assemblies Causes those DLLs to be loaded, which have the expected version number Version number is stored in the assembly by the compiler class A {...} csc /t:library A.cs A.dll (V ) class B { A a = new A();... } csc /r:A.dll B.cs B.exe (V ) stores the version number of A.dll (V ) Version number is checked when the assembly is loaded Call: B-loads B.exe -finds a reference to A.dll (V ) -loads A.dll in version V (even if there are other versions of A.dll) avoids "DLL hell"

14 Private and Public Assemblies Private Assembly is used by only one application resides in the application directory does not have a "strong name" cannot be signed Public Assembly (or shared assembly) can be used by all applications resides in the Global Assembly Cache (GAC) must have a "strong name" can be signed GAC can hold assemblies with the same name but with different version numbers

15 Strong Names Consist of 4 parts the name of the assembly (e.g. A.dll) the version number of the assembly (e.g ) the culture of the assembly (System.Globalization.CultureInfo) the public key of the assembly Version number Major.Minor.Build.Revision Build and Revision can be specified as * in the AssemblyVersion Attribute: [assembly:AssemblyVersion("1.0.*")] The compiler chooses suitable values then. using System.Reflection; [assembly:AssemblyVersion(" ")] [assembly:AssemblyCulture("en-US")] [assembly:AssemblyKeyFile("myKeyFile.snk")] class A {... } default: default: neutral can be set with attributes

16 Signing Assemblies Using Public Key Cryptography 1. Generate a key file with sn.exe (Strong Name Tool) sn /k myKeyFile.snk 2. Sign the assembly with the AssemblyKeyFile attribute [assembly:AssemblyKeyFile("myKeyFile.snk")] public class A {...} myKeyFile.snk is generated and contains: public key (128 bytes) private key (436 bytes) During compilation the assembly is signed with the private key the public key is stored in the assembly

17 Checking the Signature Signing (during compilation) public key:a1690a5ea44bab... signature:3f78b65a01e6f3... codecheck sum private key A.dll Checking (during loading) public key:a1690a5ea44bab... signature:3f78b65a01e6f3... code A.dll references public key of A.dll: a1690a5ea44bab... B.exe check sum equal?

18 Visibility Modifier "internal" Like public, but restricted to the declaring assembly internal class C {... } namespace A namespace B assembly X.dllassembly Y.dll C can be imported into other namespaces of the declaring assembly (like a public class) C cannot be used even in the same namespace if this namespace is in different assembly