tips and tricks: 10 things to avoid if you want apps to work on future clr versions robert...
TRANSCRIPT
Tips and Tricks: 10 Things to Tips and Tricks: 10 Things to Avoid if You Want Apps to Avoid if You Want Apps to Work on Future CLR Work on Future CLR VersionsVersionsRobert Villahermosa, Robert KennyRobert Villahermosa, Robert KennyFUNL01FUNL01Microsoft CorporationMicrosoft Corporation
2
In English: Top 5 .NET In English: Top 5 .NET Framework and Top 5 OS Framework and Top 5 OS Compatibility IssuesCompatibility Issues
Robert Villahermosa, Robert KennyRobert Villahermosa, Robert KennyFUNL01FUNL01Microsoft CorporationMicrosoft Corporation
3
OverviewOverview
BackgroundBackground
Top five .NET Breaking ChangesTop five .NET Breaking Changes
Top five ways to ensure your Top five ways to ensure your application will be incompatibleapplication will be incompatible
QuestionsQuestions
4
BackgroundBackgroundWhat and why?What and why?
What is compatibility?What is compatibility?Ability to run applications built on older versions of the Ability to run applications built on older versions of the platform to run on the latest versionplatform to run on the latest version
Ability for older applications to benefit from new Ability for older applications to benefit from new capabilities of the latest platform (ex FUS)capabilities of the latest platform (ex FUS)
Why is it important?Why is it important?End-Users: Their applications just work when running End-Users: Their applications just work when running them on their latest machinesthem on their latest machines
Developers: Minimizes the work required to move to Developers: Minimizes the work required to move to newer versions of the platformnewer versions of the platform
IT Admins: Greater confidence in deploying new versions IT Admins: Greater confidence in deploying new versions of the product and allowing developers to take of the product and allowing developers to take dependencies on the newer platformdependencies on the newer platform
5
BackgroundBackgroundWhy would we break you?Why would we break you?
All breaking changes evaluated for the All breaking changes evaluated for the trade-off between preserving compatibility trade-off between preserving compatibility and the value of the change to customers and the value of the change to customers
Potential Justifications for a breaking Potential Justifications for a breaking changechange
SecuritySecurity
DeterminismDeterminism
Standards ComplianceStandards Compliance
New featuresNew features
CorrectnessCorrectness
6
Breaking Change #5Breaking Change #5Enterprise Library Application Enterprise Library Application BlocksBlocks
The BreakThe BreakCustomers who used the January 2005 release of the Customers who used the January 2005 release of the Enterprise Library Application Blocks will run into Enterprise Library Application Blocks will run into “Unrecognized Attribute” or “Unrecognized configuration “Unrecognized Attribute” or “Unrecognized configuration section” errors if they run their application against section” errors if they run their application against WhidbeyWhidbey
The Blocks are doing a validation of the v1.1 The Blocks are doing a validation of the v1.1 configuration schema on the new v2.0 configuration file, configuration schema on the new v2.0 configuration file, so fail when they run into added sectionsso fail when they run into added sections
The RationaleThe RationaleMost of the apps encountered in the field that used the Most of the apps encountered in the field that used the Enterprise Library Blocks redistributed the runtime they Enterprise Library Blocks redistributed the runtime they were built againstwere built against
The fix required hacking of String.StartsWith() and was The fix required hacking of String.StartsWith() and was stomach churning to everyone who considered itstomach churning to everyone who considered it
7
Breaking Change #5Breaking Change #5Enterprise Library Application Enterprise Library Application BlocksBlocks
MitigationsMitigationsThis only impacts applications using the This only impacts applications using the January Application Block ReleaseJanuary Application Block Release
Most apps encountered in the field run in Most apps encountered in the field run in environments with the v1.1 runtime environments with the v1.1 runtime installed and can take advantage of installed and can take advantage of Side-By-SideSide-By-Side
WorkaroundsWorkarounds
Upgrade to the June release of the Upgrade to the June release of the Application BlocksApplication Blocks
8
Breaking Change #4Breaking Change #4Dotfuscator obfuscated assembliesDotfuscator obfuscated assemblies
The BreakThe BreakApplications that use the original Dotfuscator Applications that use the original Dotfuscator will not run under partial trustwill not run under partial trustThe impact here is largely with Dotfuscated The impact here is largely with Dotfuscated ASP.NET third-party controls ASP.NET third-party controls
The RationaleThe RationaleThe versions of the Dotfuscator the shipped The versions of the Dotfuscator the shipped with Visual Studio 2002 and Visual Studio 2003 with Visual Studio 2002 and Visual Studio 2003 emit invalid metadata that describes value emit invalid metadata that describes value types (such as byte) as reference typestypes (such as byte) as reference typesAllowing this in v2.0 for partially trusted Allowing this in v2.0 for partially trusted applications opens up a type holeapplications opens up a type hole
9
Breaking Change #4Breaking Change #4Dotfuscator obfuscated assembliesDotfuscator obfuscated assemblies
MitigationsMitigationsThis only impacts applications running in This only impacts applications running in partial trustpartial trust
WorkaroundsWorkaroundsPreemptive (owners of Dotfuscator) have Preemptive (owners of Dotfuscator) have released a patch that updates an released a patch that updates an obfuscated binary with the correct obfuscated binary with the correct metadatametadata
The assembly can be granted full trustThe assembly can be granted full trust
10
Breaking Change #3Breaking Change #3Type checking in User Defined Type Type checking in User Defined Type (UDT) Columns(UDT) Columns
The BreakThe BreakWe now check do a type check for data entered We now check do a type check for data entered into UDT Columnsinto UDT Columns
You can no longer assign values to UDT You can no longer assign values to UDT Columns that are not of the UDT typeColumns that are not of the UDT type
The RationaleThe RationaleUsing untyped ‘Object’ storage for UDT’s Using untyped ‘Object’ storage for UDT’s compromised type checkingcompromised type checking
We wanted consistency with UDT support in We wanted consistency with UDT support in SQL ServerSQL Server
11
Type checking in User Type checking in User Defined Type (UDT) Defined Type (UDT) ColumnsColumns
12
Breaking Change #3 Breaking Change #3 Type checking in User Defined Type Type checking in User Defined Type (UDT) Columns(UDT) Columns
MitigationMitigationNoneNone
WorkaroundsWorkaroundsExplicitly forego type checking by setting Explicitly forego type checking by setting UDT type to ‘Object’UDT type to ‘Object’
13
Breaking Change #2Breaking Change #2XHTML conformanceXHTML conformance
The BreakThe BreakThe HTML rendered by ASP.NET apps is slightly The HTML rendered by ASP.NET apps is slightly different in v2.0 than in v1.1different in v2.0 than in v1.1Control naming conventions for non id’ed Control naming conventions for non id’ed controls and container controls have changed, controls and container controls have changed, client side scripts using hard coded ids might client side scripts using hard coded ids might breakbreak
The RationaleThe RationaleStandards ConformanceStandards ConformanceXHtml conformant rendering was one of the top XHtml conformant rendering was one of the top requests from customers for the v2.0 releaserequests from customers for the v2.0 release
14
Breaking Change #2Breaking Change #2XHTML conformanceXHTML conformance
MitigationsMitigationsOnly affects apps that had dependency Only affects apps that had dependency on specific rendering generated in v1.1on specific rendering generated in v1.1Default rendering in v2.0 is XHtml 1.0 Default rendering in v2.0 is XHtml 1.0 Transitional conformantTransitional conformant
WorkaroundsWorkaroundsAdd the configuration switch to the Add the configuration switch to the web.config file of each ASP.NET web.config file of each ASP.NET application affected:application affected:
<system.web><system.web><xhtmlConformance mode=“Legacy"/><xhtmlConformance mode=“Legacy"/>
<system.Web><system.Web>
15
Breaking Change #1Breaking Change #1 Assembly Textual Identity Parsing Assembly Textual Identity Parsing
The BreakThe BreakAssembly textual identity parsing is now Assembly textual identity parsing is now stricter and can fail in several situations stricter and can fail in several situations where it previously passedwhere it previously passed
APIs that generate or use assembly APIs that generate or use assembly textual identities (e.g. assembly resolve textual identities (e.g. assembly resolve hook) may now get strings that have hook) may now get strings that have special characters escapedspecial characters escaped
The RationaleThe RationaleWe wanted to notify users of errors, We wanted to notify users of errors, instead of silently ignoring theminstead of silently ignoring them
16
Examples of breaking identitiesExamples of breaking identities
//Example 1: Bad attribute values e.g. 5 part version numberAssembly.Load("myAssembly, version=1.0.0.0.0“);
//Example 2: Blank AttributesAssembly.Load(“myAssembly, Version=2.0.0.0,Culture=Neutral, ,”)
//Example 3: Assembly names with characters that need to be escaped such as ‘’’Assembly.Load(“Rob’sAssembly”);
Breaking Change #1Breaking Change #1Fusion Textual Identity ParsingFusion Textual Identity Parsing
17
Assembly Textual Assembly Textual Identity ParsingIdentity Parsing
18
Breaking Change #1Breaking Change #1Fusion Textual Identity ParsingFusion Textual Identity Parsing
MitigationsMitigationsUnknown attributes allowed Unknown attributes allowed Assembly.Load(“myAssembly, version=1.0.0.0, Assembly.Load(“myAssembly, version=1.0.0.0,
foo=bar”);foo=bar”);
Customer WorkaroundCustomer WorkaroundModify the applications .exe.config Modify the applications .exe.config file with the following switchfile with the following switch<configuration> <configuration>
<runtime><runtime><useLegacyIdentityFormat <useLegacyIdentityFormat
enabled="1" />enabled="1" /></runtime> </runtime>
</configuration></configuration>
19
Top Five Ways To Ensure…Top Five Ways To Ensure……your application will be …your application will be incompatibleincompatible
All the way from the home office in All the way from the home office in Redmond, WARedmond, WA
The five best ways to ensure your The five best ways to ensure your application doesn’t work on the next application doesn’t work on the next OS releaseOS release
20
Number FiveNumber FiveIgnore Window sessionsIgnore Window sessions
Sessions separate multiple logonsSessions separate multiple logonsTerminal ServerTerminal ServerFast User SwitchingFast User Switching
Windows Vista:Windows Vista:Services run in session 0 Services run in session 0 First user will log into session 1!First user will log into session 1!Session 0 is not an interactive session – No UISession 0 is not an interactive session – No UI
When using named objectsWhen using named objectsALWAYS specify Global\ or Local\ namespaceALWAYS specify Global\ or Local\ namespace
FindWindow/SendMessage doesn’t work FindWindow/SendMessage doesn’t work across sessionsacross sessions
21
Number FourNumber FourIgnore newer hardwareIgnore newer hardware
16 bit components not supported on 16 bit components not supported on 64 bit OS64 bit OS
Many older installers use 16 bit Many older installers use 16 bit setup.exesetup.exe
32 bit drivers not supported on 64 bit 32 bit drivers not supported on 64 bit OSOS
WIN64 architecture WIN64 architecture doesdoes support support x86 codex86 code
GetNativeSystemInfo returns GetNativeSystemInfo returns truetrue system infosystem info
GetSystemInfo returns info relative to GetSystemInfo returns info relative to WOW emulated environmentWOW emulated environment
22
Number ThreeNumber ThreeHardcode your file and directory Hardcode your file and directory locationslocations
ALWAYS use SHGetFolderPathALWAYS use SHGetFolderPathEnvironment.GetFolderPath for managed Environment.GetFolderPath for managed codecode
Store application data in Store application data in CSIDL_APPDATACSIDL_APPDATA
Do not store user files and settings in the Do not store user files and settings in the
exe directoryexe directory
Documents and Settings is being Documents and Settings is being renamedrenamed
Will be called “Users” in Windows VistaWill be called “Users” in Windows Vista
Directory layout being flattenedDirectory layout being flattened
23
Number TwoNumber TwoPretend the registry is your Pretend the registry is your private playgroundprivate playground
DO NOT read undocumented registry DO NOT read undocumented registry valuesvalues
Current REG_SZ types may be Current REG_SZ types may be converted to REG_EXPAND_SZconverted to REG_EXPAND_SZ
New routines for reading registryNew routines for reading registryBoth expand REG_EXPAND_SZ if desiredBoth expand REG_EXPAND_SZ if desired
SHRegGetValue >= XP SP2SHRegGetValue >= XP SP2
RegGetValue >= Srv03 SP1RegGetValue >= Srv03 SP1
24
Number OneNumber OneChoose not to run on the OSChoose not to run on the OS
Most common “incompatibility” problemMost common “incompatibility” problemApplication almost always worksApplication almost always works
Poor customer experiencePoor customer experience
Check against minimally supported OSCheck against minimally supported OSIf (osVersion >= 6) printf(“Windows Vista and If (osVersion >= 6) printf(“Windows Vista and newer”);newer”);
Better yet determine if your required feature Better yet determine if your required feature exists:exists:
OpenService(hScm,“CiSvc”,GENERIC_READ);OpenService(hScm,“CiSvc”,GENERIC_READ);
GetProcAddress(hShell32, “SHRegGetValue”);GetProcAddress(hShell32, “SHRegGetValue”);
25
OS Version CheckOS Version CheckUsing VerifyVersionInfoUsing VerifyVersionInfo
BOOL IsVistaOrNewer() {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, osVersionCondition = VerSetConditionMask(0, VER_MAJORVERSION,VER_MAJORVERSION, VER_GREATER_EQUALVER_GREATER_EQUAL);); if (VerifyVersionInfo(&osVersion, VER_MAJORVERSION,if (VerifyVersionInfo(&osVersion, VER_MAJORVERSION, osVersionCondition)) {osVersionCondition)) { return TRUE;return TRUE; // Vista// 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
OS Version CheckOS Version CheckUsing GetVersionExUsing GetVersionExBOOL IsVistaOrNewer()BOOL IsVistaOrNewer(){{ OSVERSIONINFOEX osVersion;OSVERSIONINFOEX osVersion; osVersion.dwOSVersionInfoSize = osVersion.dwOSVersionInfoSize = sizeof(osVersion);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
OS Version CheckOS Version CheckUsing InstallShield scriptUsing InstallShield script
Dlg_SdWelcome: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) thenif (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
SummarySummary
Check OS version numbers with careCheck OS version numbers with care
Treat the registry with respectTreat the registry with respect
Use SHGetFolderPathUse SHGetFolderPath
Pay attention to newer hardwarePay attention to newer hardware
Pay attention to windows sessionsPay attention to windows sessions
29
Most Applications Just Most Applications Just Work!Work!
Our in-house .NET Framework Our in-house .NET Framework compatibility suites have pass rates compatibility suites have pass rates of of over 90%over 90%
Windows compatibility rates have Windows compatibility rates have historically been in the same range, historically been in the same range, and we do not expect any changes and we do not expect any changes for for Windows VistaWindows Vista
We are providing you with this We are providing you with this information now to drive that number information now to drive that number even higher in the next releaseeven higher in the next release
30
Most Apps Just Work!Most Apps Just Work!
Quake II.NET: A Managed C++ app Quake II.NET: A Managed C++ app built on v1.0 of the .NET FXbuilt on v1.0 of the .NET FX
2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.