Microsoft tackles .Net Framework compatibility

04.05.2016
Microsoft this week is offering developers guidance on dealing with its .Net Framework programming model and compatibility issues around it.

Specifically, the company advises developers to target newer versions of .Net Framework, but they shouldn't retarget existing projects to the latest update unless absolutely necessary.

By not retargeting, applications will take advantage of compatibility "quirks," said Mike Rousos, a software engineer on Microsoft's .Net team. Quirking refers to compatibility issue mitigation of having two separate code paths in the framework and choosing which path to take based on the version targeted by the application.

"Because many .Net Framework compatibility issues are mitigated in this way, it's possible to avoid many potential issues when running on newer .Net Framework versions by leaving the targeted .Net Framework version unchanged for an app," Rousos said. "Quirking behavior is automatically determined based on the .Net Framework the app targets, but can be overridden by developers using application or machine configuration settings." Not all compatibility issues can be quirked due to security and technical considerations.

Rousos said using newer versions of the framework is better "because many compatibility issues in 4.x versions of the .Net Framework have been fixed in subsequent versions. For example, there are fewer compatibility issues moving between 4.0 and 4.6 than between 4.0 and 4.5."

Microsoft recently discontinued some versions of .Net framework. But targeting of these frameworks while running on a new framework will continue to be supported as per the newer framework's support policy.

Developers need to test an app on any version of the framework it's expected to run on, said Rousos. Microsoft recommends using compatibility tools like API Portability Analyzer and .Net Framework Compatibility Analyzers to identify potential problem areas. Through the use of compatibility switches, developers can enable or disable individual compatibility quirks. "These 'compatibility switches' can be useful for allowing a developer to target a newer .Net Framework version in order to use new .Net functionality while still opting out of some changes that are known to affect the app," said Rousos. Switches can be set via configuration file settings, environment variables, or programmatically in source code.

Additionally, developers need to test an application if it's rebuilt using newer compilers. There are sets of changes between C# and Visual Basic compilers that cannot be quirked but do not occur at runtime. "For example, developers must be intentional when rebuilding apps with newer compilers, because of rare differences between how the C# 4.0 compiler generates IL and how the C# 5.0 compiler generates IL," Rousos said.

The advent of the .Net Framework 4.0 meant that all versions numbered 4.x are installed as in-place updates, so only one 4.x .Net Framework is installed on a computer at a time. Applications that ran on .Net 4.0, for example, may need to run on version 4.6 after an upgrade to the framework.

(www.infoworld.com)

Paul Krill

Zur Startseite