4. If you would like to share in our events, please write to us at prakuma@microsoft.com
5.
6. Agenda General Framework Updates Base Class Library Updates C# - Language Innovations NO PIA – Inside look WPF Improvements Parallel Extensions Dynamic Language Runtime Not covering MEF Code Contracts …….
8. General Framework updates New client profile Smaller footprint Removes unnecessary libraries from client apps Default target framework for many project templates Side by side execution of .NET framework versions Out of Process – New Roll Forward Settings In Process - Important for hosting scenarios e.g. add-in frameworks
13. Now: side-by-side CLR versions in a process2.0 add-in 3.0 add-in 3.5 add-in 4.0 add-in 3.5 .NET 4.0 3.0 .NET 2.0 Host Process (i.e. Outlook)
14. Base class library updates New classes and interfaces SortedSet Lazy<T>, IObservable<T>, Iobserver<T> Tuple, BigInteger, Complex System.IO.MemoryMappedFiles New or improved methods String.IsNullOrWhitespace String.Concat String.Join Stream.CopyTo Tail recursion optimization for x64 JIT Function calls itself at the end e.g. fact n = n* fact(n-1);
15.
16.
17. Co- and Contra-variance .NET arrays are co-variant string[] strings = GetStringArray(); Process(strings); …but not safelyco-variant void Process(object[] objects) { … } void Process(object[] objects) { objects[0] = "Hello"; // Ok objects[1] = newButton(); // Exception! } Until now, C# generics have been invariant List<string> strings = GetStringList(); Process(strings); C# 4.0 supports safe co- and contra-variance void Process(IEnumerable<object> objects) { … } void Process(IEnumerable<object> objects) { // IEnumerable<T> is read-only and // therefore safely co-variant }
18. Variance in C# 4.0 Supported for interface and delegate types “Statically checked definition-site variance” Value types are always invariant IEnumerable<int> is notIEnumerable<object> Similar to existing rules for arrays ref and out parameters need invariant type
19. Demo Co- and Contra-variance support for generics varVs dynamic
20. Primary Interop Assemblies (PIA) Interoperability matters “COM is not dead; COM is done” (Don Box) E.g. Office automation APIs Introduction of PIAs to bridge with COM Inter-op assemblies translate between managed code and COM The fun part (PIA pain points): Versioning headaches (publisher policy) Deployment horror of huge files (~MB) Also hard to create (TLBIMP, ILASM etc.) All kinds of Interop can be hard Visit clrinterop.codeplex.com for great tools
21. Go Away, PIA! - NO PIA Embedding of interop types and members Happens at compile time No need to redistribute the PIAs “Play for play” (only what you use gets copied) Behind the scenes Type Equivalence Gets specified using [TypeIdentifier] E.g. COM GUID can be used as identified Vtable gaps for interface compatibility
22. No-PIA behind the scenes var app = new Word.Application(); app.ActiveDocument.Save(); _Document interface [TypeIdentifier] [Guid(…)] Interface _Document { void Save(); void _VtblGap1_168(); }
26. Parallel Extensions for .NET Parallel task library Provides task based model for executing code asynchronously Takes advantage of multiple cores and advances algorithms Provide model for cancellation, continuation, exception handling etc. The preferred way to execute async work in .NET System.Threading.Tasks.Parallel class AsParallel extension methods ForEach and ForEach<T>() Parallel LINQ Parallel implementation of LINQ to objects Merge options – how to bring the results back together
28. Dynamic Language Runtime Call dynamic languages from .NET Enable scripting of your application Take advantage of dynamic language features from .NET Call .NET from dynamic languages Take advantage of the BCL Two main types / keywords in the framework Dynamic – Enables late binding to objects ExpandoObject – dynamically add members (prop, method, event) Framework doesn’t include scripting engine Download full DLR and appropriate language to interoperate http://dlr.codeplex.com
29.
30. .NET USER GROUP http://www.sgdotnet.org My .NET Facebook Group - DOTNetGeeks
Editor's Notes
MESSAGING:Run both 2.0-based and 4.0-based CLR in the same processOld components use old CLRNew components use new CLR Configuration file and hosting APIs give you fine-grained control
MESSAGING:Office has thousands of APIs for addins exposed through COM. But COM was designed for native code. Interop Assemblies help “translate” between managed and native code by containing all the marshalling data necessary to make communication possible. For each interface, struct, enum, delegate, and member, contains a managed equivalent with marshalling data.MESSAGING:Let’s look at Office as an example. Add-ins in Excel, for instance, may very well need to talk to each other -> Because they have to talk to each other, they have to be using the same types for Excel -> Because of the way the type system works in the CLR, these types must also be in the same assembly -> So, the assembly is required to be in a common location (e.g. the GAC) in order for the add-ins to function properly.Well, Office currently does not require the .NET Framework to be installed on a machine. If a machine doesn’t have .NET installed, there’s no GAC, and hence nothing to deploy the PIA into. Herein lies the problem. Even if an add-in is only using a single function, enum, etc. from the interop assembly, the add-in must deploy the entire PIA along with itself. Office PIA is around 10-20mb, it’s HUGE. So you might have a 100k add-in “bringing along” a 20mb PIA.
MESSAGING:There are two primary things that enable PIAs to be buried, forever, never to rise again. Compiler enhancements (this embedding works down to the method level even, so even a full interface is not required).Runtime enhancementsEven though they are in different assembliesEven though they may have different subsetsHence, type equivalence allows two interfaces, enums, delegates and plain-old-data-structures to mark themselves as equivalent with each other.
MESSAGING:PLINQ is a technology that allows developers to _easily_ leveragemanycore. The great thing about PLINQ is that if you are using LINQ-to-objects, there is a very minimal impact to your code in order for it to use PLINQ. All it takes to use PLINQ is adding “.AsParallel()” to your query. This will turn the query into a PLINQ query and will use the PLINQ execution engine when executed.One small change, and your code now takes advantage of all the hardware available to you.NOTES:AsParallel() works by returning an IParallelEnumerable so every subsequent query operator works against the new IParallelEnumerable rather than the normal IEnumerable. See the hands-on lab for Parallel Extensions for more details.