SlideShare a Scribd company logo
Visual Studio 2010, .NET 4, ASP.NET 4 & more…13th April 2011
Agenda
Few things to note….Feedback is very important to us!
If you would like to share in our events, please write to us at prakuma@microsoft.com
Our team blog www.innovativesingapore.com.NET 4.0 DemystifiedApril 13 2011Sandeep JoshiBarclays CapitalMCT, Former MVP C#sandeep_mvp@hotmail.com
AgendaGeneral Framework Updates Base Class Library UpdatesC# - Language InnovationsNO PIA – Inside lookWPF ImprovementsParallel ExtensionsDynamic Language RuntimeNot coveringMEFCode Contracts…….
Journey so far…SP1You’re here!3.53.0.NET 1.0.NET 1.1.NET 2.0.NET 4200220032008 CTP2005-08CLR 1.0CLR 1.1CLR 2.0CLR 4
General Framework updatesNew client profileSmaller footprintRemoves unnecessary libraries from client appsDefault target framework for many project templatesSide by side execution of .NET framework versionsOut of Process – New Roll Forward SettingsIn Process - Important for hosting scenarios e.g. add-in frameworks
Runtime side-by-side(SxS)Out-of-process side-by-side(SxS) storyAllows for good application compatibilityLayered cake modelSame story for .NET 4Application can roll-forward to CLR v4.0NET 4.0 is a highly compatible release but does not auto–roll forward
You must add a configuration file with a specific switch to get 3.5 apps to run on 4.0Roll-forward to new runtime<configuration><startupuseLegacyV2RuntimeActivationPolicy="true" > 		<supportedRuntime version="v2.0.50727"/> 		<supportedRuntime version="v4.0"/> </startup> </configuration>RationaleBetter test you application is really “blessed” to run on .NET 4 without any changes…
CLR 4 - In-Process Side-By-SideAdd-In Scenario
Past : Only one CLR version in a process
Now: side-by-side CLR versions in a process2.0 add-in3.0 add-in3.5 add-in4.0 add-in3.5.NET 4.03.0.NET 2.0Host Process (i.e. Outlook)
Base class library updatesNew classes and interfacesSortedSetLazy<T>, IObservable<T>, Iobserver<T>Tuple, BigInteger, ComplexSystem.IO.MemoryMappedFilesNew or improved methodsString.IsNullOrWhitespaceString.ConcatString.JoinStream.CopyToTail recursion optimization for x64 JITFunction calls itself at the end  e.g. fact n = n* fact(n-1);
DemoNew BCL TypesTuple
BigIntegerC# 4.0 Language InnovationsDynamic Type supportOffice ProgrammabilityDynamic language integration – more laterImproved COM InteroperabilityCo- and Contra-variance support for genericsCo-variance –use more derived typeContra-variance – use less derived type
Co- and Contra-variance.NET arrays are co-variantstring[] strings = GetStringArray();Process(strings);…but not safelyco-variantvoid Process(object[] objects) { … }void Process(object[] objects) {   objects[0] = "Hello";       // Ok   objects[1] = newButton();  // Exception!}Until now, C# generics have been invariantList<string> strings = GetStringList();Process(strings);C# 4.0 supports safe co- and contra-variancevoid Process(IEnumerable<object> objects) { … }void Process(IEnumerable<object> objects) {// IEnumerable<T> is read-only and// therefore safely co-variant}
Variance in C# 4.0Supported for interface and delegate types“Statically checked definition-site variance”Value types are always invariantIEnumerable<int> is notIEnumerable<object>Similar to existing rules for arraysref and out parameters need invariant type
DemoCo- and Contra-variance support for genericsvarVs dynamic
Primary Interop Assemblies (PIA)Interoperability matters“COM is not dead; COM is done” (Don Box)E.g. Office automation APIsIntroduction of PIAs to bridge with COMInter-op assemblies translate between managed code and COMThe 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 hardVisit clrinterop.codeplex.com for great tools
Go Away, PIA!  - NO PIA Embedding of interop types and membersHappens at compile timeNo need to redistribute the PIAs“Play for play” (only what you use gets copied)Behind the scenesType EquivalenceGets specified using [TypeIdentifier]E.g. COM GUID can be used as identifiedVtable gaps for interface compatibility
No-PIA behind the scenesvar app = new Word.Application();app.ActiveDocument.Save();     _Document interface[TypeIdentifier][Guid(…)]Interface _Document{void Save();void _VtblGap1_168();}
DemoNO PIA
Type EquivalenceWPF ImprovementsNew ControlsDataGrid, Calender and DatePickerImproved text renderingDesigner Enhancements DataBinding UIEasier style and resource managementImproved property editing – brushesWindows 7 shell integrationJump lists and task bar integration
DemoWPF – DataGrid
Parallel Extensions for .NETParallel task libraryProvides task based model for executing code asynchronouslyTakes advantage of multiple cores and advances algorithmsProvide model for cancellation, continuation, exception handling etc.The preferred way to execute async work in .NETSystem.Threading.Tasks.Parallel classAsParallel extension methodsForEach and ForEach<T>()Parallel LINQParallel implementation of LINQ to objectsMerge options – how to bring the results back together
DemoParallel ForEachParallel LINQTask Continuation
Dynamic Language RuntimeCall dynamic languages from .NETEnable scripting of your applicationTake advantage of dynamic language features from .NET Call .NET from dynamic languages Take advantage of the BCLTwo main types / keywords in the frameworkDynamic – Enables late binding to objectsExpandoObject – dynamically add members (prop, method, event)Framework doesn’t include scripting engineDownload full DLR and appropriate language to interoperatehttp://dlr.codeplex.com

More Related Content

.NET 4 Demystified - Sandeep Joshi

  • 1. Visual Studio 2010, .NET 4, ASP.NET 4 & more…13th April 2011
  • 3. Few things to note….Feedback is very important to us!
  • 4. If you would like to share in our events, please write to us at prakuma@microsoft.com
  • 5. Our team blog www.innovativesingapore.com.NET 4.0 DemystifiedApril 13 2011Sandeep JoshiBarclays CapitalMCT, Former MVP C#sandeep_mvp@hotmail.com
  • 6. AgendaGeneral Framework Updates Base Class Library UpdatesC# - Language InnovationsNO PIA – Inside lookWPF ImprovementsParallel ExtensionsDynamic Language RuntimeNot coveringMEFCode Contracts…….
  • 7. Journey so far…SP1You’re here!3.53.0.NET 1.0.NET 1.1.NET 2.0.NET 4200220032008 CTP2005-08CLR 1.0CLR 1.1CLR 2.0CLR 4
  • 8. General Framework updatesNew client profileSmaller footprintRemoves unnecessary libraries from client appsDefault target framework for many project templatesSide by side execution of .NET framework versionsOut of Process – New Roll Forward SettingsIn Process - Important for hosting scenarios e.g. add-in frameworks
  • 9. Runtime side-by-side(SxS)Out-of-process side-by-side(SxS) storyAllows for good application compatibilityLayered cake modelSame story for .NET 4Application can roll-forward to CLR v4.0NET 4.0 is a highly compatible release but does not auto–roll forward
  • 10. You must add a configuration file with a specific switch to get 3.5 apps to run on 4.0Roll-forward to new runtime<!-- Compiled for 2.0, run against 4.0 --><configuration><startupuseLegacyV2RuntimeActivationPolicy="true" > <supportedRuntime version="v2.0.50727"/> <supportedRuntime version="v4.0"/> </startup> </configuration>RationaleBetter test you application is really “blessed” to run on .NET 4 without any changes…
  • 11. CLR 4 - In-Process Side-By-SideAdd-In Scenario
  • 12. Past : Only one CLR version in a process
  • 13. Now: side-by-side CLR versions in a process2.0 add-in3.0 add-in3.5 add-in4.0 add-in3.5.NET 4.03.0.NET 2.0Host Process (i.e. Outlook)
  • 14. Base class library updatesNew classes and interfacesSortedSetLazy<T>, IObservable<T>, Iobserver<T>Tuple, BigInteger, ComplexSystem.IO.MemoryMappedFilesNew or improved methodsString.IsNullOrWhitespaceString.ConcatString.JoinStream.CopyToTail recursion optimization for x64 JITFunction calls itself at the end e.g. fact n = n* fact(n-1);
  • 16. BigIntegerC# 4.0 Language InnovationsDynamic Type supportOffice ProgrammabilityDynamic language integration – more laterImproved COM InteroperabilityCo- and Contra-variance support for genericsCo-variance –use more derived typeContra-variance – use less derived type
  • 17. Co- and Contra-variance.NET arrays are co-variantstring[] strings = GetStringArray();Process(strings);…but not safelyco-variantvoid Process(object[] objects) { … }void Process(object[] objects) { objects[0] = "Hello"; // Ok objects[1] = newButton(); // Exception!}Until now, C# generics have been invariantList<string> strings = GetStringList();Process(strings);C# 4.0 supports safe co- and contra-variancevoid Process(IEnumerable<object> objects) { … }void Process(IEnumerable<object> objects) {// IEnumerable<T> is read-only and// therefore safely co-variant}
  • 18. Variance in C# 4.0Supported for interface and delegate types“Statically checked definition-site variance”Value types are always invariantIEnumerable<int> is notIEnumerable<object>Similar to existing rules for arraysref and out parameters need invariant type
  • 19. DemoCo- and Contra-variance support for genericsvarVs dynamic
  • 20. Primary Interop Assemblies (PIA)Interoperability matters“COM is not dead; COM is done” (Don Box)E.g. Office automation APIsIntroduction of PIAs to bridge with COMInter-op assemblies translate between managed code and COMThe 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 hardVisit clrinterop.codeplex.com for great tools
  • 21. Go Away, PIA! - NO PIA Embedding of interop types and membersHappens at compile timeNo need to redistribute the PIAs“Play for play” (only what you use gets copied)Behind the scenesType EquivalenceGets specified using [TypeIdentifier]E.g. COM GUID can be used as identifiedVtable gaps for interface compatibility
  • 22. No-PIA behind the scenesvar app = new Word.Application();app.ActiveDocument.Save(); _Document interface[TypeIdentifier][Guid(…)]Interface _Document{void Save();void _VtblGap1_168();}
  • 24. Type EquivalenceWPF ImprovementsNew ControlsDataGrid, Calender and DatePickerImproved text renderingDesigner Enhancements DataBinding UIEasier style and resource managementImproved property editing – brushesWindows 7 shell integrationJump lists and task bar integration
  • 26. Parallel Extensions for .NETParallel task libraryProvides task based model for executing code asynchronouslyTakes advantage of multiple cores and advances algorithmsProvide model for cancellation, continuation, exception handling etc.The preferred way to execute async work in .NETSystem.Threading.Tasks.Parallel classAsParallel extension methodsForEach and ForEach<T>()Parallel LINQParallel implementation of LINQ to objectsMerge options – how to bring the results back together
  • 28. Dynamic Language RuntimeCall dynamic languages from .NETEnable scripting of your applicationTake advantage of dynamic language features from .NET Call .NET from dynamic languages Take advantage of the BCLTwo main types / keywords in the frameworkDynamic – Enables late binding to objectsExpandoObject – dynamically add members (prop, method, event)Framework doesn’t include scripting engineDownload full DLR and appropriate language to interoperatehttp://dlr.codeplex.com
  • 29. DemoDLR – interoperating with Python from C#Q&A
  • 30. .NET USER GROUPhttp://www.sgdotnet.orgMy .NET Facebook Group - DOTNetGeeks

Editor's Notes

  1. 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
  2. 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 -&gt; Because they have to talk to each other, they have to be using the same types for Excel -&gt; Because of the way the type system works in the CLR, these types must also be in the same assembly -&gt; 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.
  3. 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.
  4. 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.