API Differences in Portable Class Library

Updated: April 2011

To make the types that are supported in the Portable Class Library work on different platforms, some changes were made to the types in the .NET Framework 4. You will encounter these changes only when you are working in a Portable Class Library project. These changes corrected inconsistencies between the different releases of the types. For example, in Silverlight, the System.Net.HttpWebRequest class contains a property named SupportsCookieContainer, but this property did not exist in the System.Net.HttpWebRequest class in the .NET Framework 4. For the Portable Class Library, the SupportsCookieContainer property was added to the .NET Framework to make the types consistent. However, the SupportsCookieContainer property is not available to .NET Framework 4 users unless they are working in a Portable Class Library project. This topic describes the changes that were made to the types and members in the .NET Framework for the Portable Class Library, and any behavioral changes you might encounter.

.NET Framework 4 Changes

When you are working in a Portable Class Library project, you will encounter the following changed types and members in the .NET Framework 4 class library.

System.ServiceModel.ClientBase<TChannel>.ChannelBase<T>

This type was added to the .NET Framework. It already existed in the Silverlight class library. It has 52 members. For more information, see the System.ServiceModel.ClientBase<TChannel>.ChannelBase<T> reference topic in the Silverlight documentation.

System.ServiceModel.Channels.IHttpCookieContainerManager

This type was added to the .NET Framework. It already existed in the Silverlight class library. It has 1 member. For more information, see the System.ServiceModel.Channels.IHttpCookieContainerManager reference topic in the Silverlight documentation.

System.Net.HttpWebRequest

Two new properties were added to System.Net.HttpWebRequest:

Member

Changes for Portable Class Library

Signature

SupportsCookieContainer property

New property.

public bool SupportsCookieContainer { get; }

AllowReadStreamBuffering property

New property.

public bool AllowReadStreamBuffering { get; set; }

System.Net.WebRequest

Two new methods were added to System.Net.WebRequest:

Member

Changes for Portable Class Library

Signature

CreateHttp(Uri) method

New method.

public HttpWebRequest CreateHttp(System.Uri requestUri)

CreateHttp(String) method

New method.

public HttpWebRequest CreateHttp(string requestUriString)

System.Net.WebResponse

Two new members were added to System.Net.WebResponse, and one method was changed.

Member

Changes for Portable Class Library

Signature

SupportsHeaders property

New property.

public bool SupportsHeaders { get; }

Dispose(Boolean) method

New method.

protected void Dispose(bool disposing)

Dispose method

Signature change.

Old: void IDisposable.Dispose()

New: public void Dispose()

System.Xml.XmlReader

Two methods were changed in System.Xml.XmlReader.

Member

Changes for Portable Class Library

Signature

Dispose method

Signature change.

Old: void IDisposable.Dispose()

New: public void Dispose()

Close method

Signature change.

Old: public abstract Close()

New: public virtual Close()

System.Xml.XmlWriter

Two methods were changed in System.Xml.XmlWriter.

Member

Changes for Portable Class Library

Signature

Dispose method

Signature change.

Old: void IDisposable.Dispose()

New: public void Dispose()

Close method

Signature change.

Old: public abstract Close()

New: public virtual Close()

System.Xml.XmlResolver

One property was changed in System.Xml.XmlResolver.

Member

Changes for Portable Class Library

Signature

Credentials property

Signature change.

Old: public abstract ICredentials Credentials { set; }

New: public virtual ICredentials Credentials { set; }

Behavioral Changes in the API

Some types and members behave differently when they are used in a Portable Class Library project.

Metadata from Type

When evaluating metadata returned from System.Type methods and properties, the equality operator may return different results on different platforms. In the .NET Compact Framework, each successive call to the Type.GetMethod method returns a new instance of System.Reflection.MethodInfo, so return values are never evaluated as equal. However, in the .NET Framework 4, calling GetMethod with the same parameters returns the same instance of MethodInfo. You must review and potentially modify your code when you are working with the following System.Reflection types: MethodInfo, FieldInfo, PropertyInfo, EventInfo, MemberInfo, MethodBase, ConstructorInfo, and ParameterInfo.

Expression Tree with Generic Types

On Windows Phone 7, a VerificationException exception is thrown when you create an expression tree that refers to a local variable that is a generic type.

Reflection on Open Generic Types

On Windows Phone 7, reflection is supported on closed generic types; however, most reflection operations are not supported on open generic types. On open generic types, only the following reflection operations are supported for Windows Phone 7:

For all other reflection operations on open generic types, a NotSupportedException exception is thrown.

See Also

Concepts

Portable Class Libraries

Change History

Date

History

Reason

April 2011

Added more information about behavior changes.

Information enhancement.

March 2011

Added topic.

Information enhancement.