Visual Studio 2010 and .NET Framework 4 Training Workshop
Presentation Outline (hidden Technical Level: 300 Intended Audience: Developers & Architects Objectives (what do you want the audience to take away): Understand the changes coming to the .NET Framework 4 Understand the goals of CLR 4
Presentation Outline: .NET Framework History and Packaging New BCL Improvements Code Contracts Type Equivalence/No-PIA In-Process SxS
What’s New In .NET Framework 4 Name Title Organization Email
A Look Back…
SP1 3.5 3.0 .NET 1.0 2002 CLR 1.0
.NET 1.1 2003 CLR 1.1
.NET 2.0
.NET 4
2005-08
2008 CTP!
CLR 2.0
CLR 4
What Is The .NET Framework?
WPF
Win Forms
DLR
ASP.NE T
WCF
LINQ
And more!
Base Class Libraries
The CLR JIT & NGEN
Garbage Collector
Security Model
Exception Handling
Loader & Binder
Base Class Library Improvements Numerics BigInteger, Complex Data Structures Tuple SortedSet, ISet I/O Memory-Mapped File Unified Cancellation Model
The goal of CLR 4 Working Better Together… In-Proc SxSManaged Extensibility Framework DLR Integration Native/Managed Interop
Faster… Threading Parallel Extensions Garbage Collection Profiling
With Fewer Bugs… Corrupted State Exceptions Code Contracts Debugging
The goal of CLR 4 Working Better Together… In-Proc SxS Managed Extensibility Framework DLR Integration Native/Managed Interop
Faster… Threading Parallel Extensions Garbage Collection Profiling
With Fewer Bugs… Corrupted State Exceptions Code Contracts Debugging
Design By Contract
Code Contracts introduce a way to specify contractual information that is not represented by a method or type’s signature alone.
What is a Contract?
A contract is… an exchange of promises between two or more parties to do, or refrain from doing, an act which is enforceable in a court of law. - Wikipedia
Why Contracts?
There upset about that? But its the best gift in the hole world. They’re upset about that? But it’s the best gift in the whole world.
Why Contracts?
Just because something compiles, doesn’t mean it works…
A Contract contains… Pre-conditions - must be true before public Rational(int numerator, int denominator) { Contract.Requires(denominator > 0); … }
Post-conditions - must be true public string GetPassword() { Contract.Ensures(Contract.Result<string>() != null); … return password; }
A Contract contains…
Invariants - must always be true [ContractInvariantMethod] protected void ObjectInvariant() { Contract.Invariant(denominator > 0); }
Code Contracts
Type Equivalence Interop Assemblies translate between managed code and COM For each interface, struct, enum, delegate, and member, contains a managed equivalent with marshalling data
However! Primary Interop Assemblies cause many pain points…
Go Away, PIA! 1. Compilers embed the portions of the interop assemblies that the addins actually use 3. Runtime ensures the embedded definitions of these types are considered equivalent
No-PIA
Existing Side-By-Side (SxS) 1.1 addin
2.0 addin
3.0 addin
3.5 addin
3.5 3.0 .NET 1.1
.NET 2.0
Host Process (i.e. Outlook)
In-Process Side-By-Side (SxS) 2.0 addin
3.0 addin
3.5 addin
4.0 addin
3.5 3.0 .NET 2.0
.NET 4.0
Host Process (i.e. Outlook)
The goal of CLR 4.0 Working Better Together… In-Proc SxSManaged Extensibility Framework DLR Integration Native/Managed Interop
Faster… Threading Parallel Extensions Garbage Collection Profiling
With Fewer Bugs… Corrupted State Exceptions Code Contracts Debugging
Why Compatibility Is Hard .NET Framework 1.1 was highly compatible with 1.0 Thread [] threads = new Thread[8]; for (int i=0; i<8; i++) { Worker worker = new Worker(); threads[i] = new ThreadStart(worker.Work); threads[i].Start(); worker.identity =i; }
Code from an Outlook addin our executives used
Why Compatibility Is Hard Thread [] threads = new Thread[8]; for (int i=0; i<8; i++) { Worker worker = new Worker(); threads[i] = new ThreadStart(worker.Work); threads[i].Start(); worker.identity =i; }
Code from an Outlook addin our executives used .NET 1.1 just slightly faster for starting threads No Executives at Microsoft could use their mail Bug wasn’t our fault – but no one cares