Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tips and Tricks: 10 Things to Avoid if You Want Apps to Work on Future CLR Versions Robert Villahermosa, Robert Kenny FUNL01 Microsoft Corporation.

Similar presentations


Presentation on theme: "Tips and Tricks: 10 Things to Avoid if You Want Apps to Work on Future CLR Versions Robert Villahermosa, Robert Kenny FUNL01 Microsoft Corporation."— Presentation transcript:

1 Tips and Tricks: 10 Things to Avoid if You Want Apps to Work on Future CLR Versions Robert Villahermosa, Robert Kenny FUNL01 Microsoft Corporation

2 2 In English: Top 5.NET Framework and Top 5 OS Compatibility Issues Robert Villahermosa, Robert Kenny FUNL01 Microsoft Corporation

3 3 Overview Background Top five.NET Breaking Changes Top five ways to ensure your application will be incompatible Questions

4 4 Background What and why? What is compatibility? Ability to run applications built on older versions of the platform to run on the latest version Ability for older applications to benefit from new capabilities of the latest platform (ex FUS) Why is it important? End-Users: Their applications just work when running them on their latest machines Developers: Minimizes the work required to move to newer versions of the platform IT Admins: Greater confidence in deploying new versions of the product and allowing developers to take dependencies on the newer platform

5 5 Background Why would we break you? All breaking changes evaluated for the trade-off between preserving compatibility and the value of the change to customers Potential Justifications for a breaking change SecurityDeterminism Standards Compliance New features Correctness

6 6 Breaking Change #5 Enterprise Library Application Blocks The Break Customers who used the January 2005 release of the Enterprise Library Application Blocks will run into “Unrecognized Attribute” or “Unrecognized configuration section” errors if they run their application against Whidbey The Blocks are doing a validation of the v1.1 configuration schema on the new v2.0 configuration file, so fail when they run into added sections The Rationale Most of the apps encountered in the field that used the Enterprise Library Blocks redistributed the runtime they were built against The fix required hacking of String.StartsWith() and was stomach churning to everyone who considered it

7 7 Breaking Change #5 Enterprise Library Application Blocks Mitigations This only impacts applications using the January Application Block Release Most apps encountered in the field run in environments with the v1.1 runtime installed and can take advantage of Side-By-Side Workarounds Upgrade to the June release of the Application Blocks

8 8 Breaking Change #4 Dotfuscator obfuscated assemblies The Break Applications that use the original Dotfuscator will not run under partial trust The impact here is largely with Dotfuscated ASP.NET third-party controls The Rationale The versions of the Dotfuscator the shipped with Visual Studio 2002 and Visual Studio 2003 emit invalid metadata that describes value types (such as byte) as reference types Allowing this in v2.0 for partially trusted applications opens up a type hole

9 9 Breaking Change #4 Dotfuscator obfuscated assemblies Mitigations This only impacts applications running in partial trust Workarounds Preemptive (owners of Dotfuscator) have released a patch that updates an obfuscated binary with the correct metadata The assembly can be granted full trust

10 10 Breaking Change #3 Type checking in User Defined Type (UDT) Columns The Break We now check do a type check for data entered into UDT Columns You can no longer assign values to UDT Columns that are not of the UDT type The Rationale Using untyped ‘Object’ storage for UDT’s compromised type checking We wanted consistency with UDT support in SQL Server

11 11 Type checking in User Defined Type (UDT) Columns

12 12 Breaking Change #3 Type checking in User Defined Type (UDT) Columns MitigationNoneWorkarounds Explicitly forego type checking by setting UDT type to ‘Object’

13 13 Breaking Change #2 XHTML conformance The Break The HTML rendered by ASP.NET apps is slightly different in v2.0 than in v1.1 Control naming conventions for non id’ed controls and container controls have changed, client side scripts using hard coded ids might break The Rationale Standards Conformance XHtml conformant rendering was one of the top requests from customers for the v2.0 release

14 14 Breaking Change #2 XHTML conformance Mitigations Only affects apps that had dependency on specific rendering generated in v1.1 Default rendering in v2.0 is XHtml 1.0 Transitional conformant Workarounds Add the configuration switch to the web.config file of each ASP.NET application affected:

15 15 Breaking Change #1 Assembly Textual Identity Parsing The Break Assembly textual identity parsing is now stricter and can fail in several situations where it previously passed APIs that generate or use assembly textual identities (e.g. assembly resolve hook) may now get strings that have special characters escaped The Rationale We wanted to notify users of errors, instead of silently ignoring them

16 16 Examples of breaking identities //Example 1: Bad attribute values e.g. 5 part version number Assembly.Load("myAssembly, version= “); //Example 2: Blank Attributes Assembly.Load(“myAssembly, Version= ,Culture=Neutral,,”) //Example 3: Assembly names with characters that need to be escaped such as ‘’’ Assembly.Load(“Rob’sAssembly”); Breaking Change #1 Fusion Textual Identity Parsing

17 17 Assembly Textual Identity Parsing

18 18 Breaking Change #1 Fusion Textual Identity Parsing Mitigations Unknown attributes allowed Assembly.Load(“myAssembly, version= , foo=bar”); Customer Workaround Modify the applications.exe.config file with the following switch

19 19 Top Five Ways To Ensure… …your application will be incompatible All the way from the home office in Redmond, WA The five best ways to ensure your application doesn’t work on the next OS release

20 20 Number Five Ignore Window sessions Sessions separate multiple logons Terminal Server Fast User Switching Windows Vista: Services run in session 0 First user will log into session 1! Session 0 is not an interactive session – No UI When using named objects ALWAYS specify Global\ or Local\ namespace FindWindow/SendMessage doesn’t work across sessions

21 21 Number Four Ignore newer hardware 16 bit components not supported on 64 bit OS Many older installers use 16 bit setup.exe 32 bit drivers not supported on 64 bit OS WIN64 architecture does support x86 code GetNativeSystemInfo returns true system info GetSystemInfo returns info relative to WOW emulated environment

22 22 Number Three Hardcode your file and directory locations ALWAYS use SHGetFolderPath Environment.GetFolderPath for managed code Store application data in CSIDL_APPDATA Do not store user files and settings in the exe directory Documents and Settings is being renamed Will be called “Users” in Windows Vista Directory layout being flattened

23 23 Number Two Pretend the registry is your private playground DO NOT read undocumented registry values Current REG_SZ types may be converted to REG_EXPAND_SZ New routines for reading registry Both expand REG_EXPAND_SZ if desired SHRegGetValue >= XP SP2 RegGetValue >= Srv03 SP1

24 24 Number One Choose not to run on the OS Most common “incompatibility” problem Application almost always works Poor customer experience Check against minimally supported OS If (osVersion >= 6) printf(“Windows Vista and newer”); Better yet determine if your required feature exists: OpenService(hScm,“CiSvc”,GENERIC_READ); GetProcAddress(hShell32, “SHRegGetValue”);

25 25 OS Version Check Using VerifyVersionInfo BOOL IsVistaOrNewer() { ULONGLONG osVersionCondition; ULONGLONG osVersionCondition; OSVERSIONINFOEX osVersion; OSVERSIONINFOEX osVersion; // Note using the VER_GREATER_EQUAL comparison // Note using the VER_GREATER_EQUAL comparison osVersion.dwOSVersionInfoSize = sizeof(osVersion); osVersion.dwOSVersionInfoSize = sizeof(osVersion); osVersion.dwMajorVersion = 6; osVersion.dwMajorVersion = 6; osVersionCondition = VerSetConditionMask(0, VER_MAJORVERSION, osVersionCondition = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL); VER_GREATER_EQUAL); if (VerifyVersionInfo(&osVersion, VER_MAJORVERSION, if (VerifyVersionInfo(&osVersion, VER_MAJORVERSION, osVersionCondition)) { osVersionCondition)) { return TRUE;// Vista return TRUE; // Vista } else if (GetLastError() != ERROR_OLD_WIN_VERSION) { } else if (GetLastError() != ERROR_OLD_WIN_VERSION) { // Handle API error // Handle API error } return FALSE; return FALSE;}

26 26 OS Version Check Using GetVersionEx BOOL IsVistaOrNewer() { OSVERSIONINFOEX osVersion; OSVERSIONINFOEX osVersion; osVersion.dwOSVersionInfoSize = sizeof(osVersion); osVersion.dwOSVersionInfoSize = sizeof(osVersion); if (GetVersionEx((LPOSVERSIONINFO)&osVersion)) { if (GetVersionEx((LPOSVERSIONINFO)&osVersion)) { // Determine if this is Windows Vista or newer // Determine if this is Windows Vista or newer // Note the >= check // Note the >= check if (osVersion.dwMajorVersion >= 6) { if (osVersion.dwMajorVersion >= 6) { // Vista // Vista return TRUE; return TRUE; } } else { } else { // Handle API error // Handle API error } return FALSE; return FALSE;}

27 27 OS Version Check Using InstallShield script Dlg_SdWelcome: szTitle = "Welcome"; szTitle = "Welcome"; // Avoid using SYSINFO.WINNT.bWinXP // Avoid using SYSINFO.WINNT.bWinXP // Note usage of >= comparison // Note usage of >= comparison if (SYSINFO.nOSMajor >= 6) then if (SYSINFO.nOSMajor >= 6) then szMsg = "Windows Vista or newer"; szMsg = "Windows Vista or newer"; else else szMsg = "Older than Vista"; szMsg = "Older than Vista"; endif; endif; //{{IS_SCRIPT_TAG(Dlg_SdWelcome) //{{IS_SCRIPT_TAG(Dlg_SdWelcome) nResult = SdWelcome( szTitle, szMsg ); nResult = SdWelcome( szTitle, szMsg ); //}}IS_SCRIPT_TAG(Dlg_SdWelcome) //}}IS_SCRIPT_TAG(Dlg_SdWelcome) if (nResult = BACK) goto Dlg_Start; if (nResult = BACK) goto Dlg_Start;

28 28 Summary Check OS version numbers with care Treat the registry with respect Use SHGetFolderPath Pay attention to newer hardware Pay attention to windows sessions

29 29 Most Applications Just Work! Our in-house.NET Framework compatibility suites have pass rates of over 90% Windows compatibility rates have historically been in the same range, and we do not expect any changes for Windows Vista We are providing you with this information now to drive that number even higher in the next release

30 30 Most Apps Just Work! Quake II.NET: A Managed C++ app built on v1.0 of the.NET FX

31 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.


Download ppt "Tips and Tricks: 10 Things to Avoid if You Want Apps to Work on Future CLR Versions Robert Villahermosa, Robert Kenny FUNL01 Microsoft Corporation."

Similar presentations


Ads by Google