KGy SOFT

WeakAssemblySerializationBinder Class

KGy SOFT Core Libraries Help
Provides a SerializationBinder instance for IFormatter implementations that can ignore version and token information of stored assembly name. This makes possible to deserialize objects stored in different version of the original assembly. It also can make any IFormatter safe in terms of prohibiting loading assemblies during the deserialization if the SafeMode property is .
See the Remarks section for details.
Inheritance Hierarchy

SystemObject
  System.Runtime.SerializationSerializationBinder
    KGySoft.Serialization.BinaryWeakAssemblySerializationBinder

Namespace:  KGySoft.Serialization.Binary
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 6.0.0-rc.1
Syntax

public sealed class WeakAssemblySerializationBinder : SerializationBinder, 
	ISerializationBinder

The WeakAssemblySerializationBinder type exposes the following members.

Constructors

  NameDescription
Public methodWeakAssemblySerializationBinder
Initializes a new instance of the WeakAssemblySerializationBinder class
Top
Properties

  NameDescription
Public propertyIgnoreAssemblyNameOnResolve
Gets or sets whether an existing assembly name is allowed to be completely ignored on deserialization.
Default value: .
Public propertyOmitAssemblyNameOnSerialize
Gets or sets whether assembly name should be completely omitted on serialization.
Default value: .
Public propertySafeMode
Gets or sets whether loading assemblies is prohibited on deserialization.
Default value: .
Top
Methods

  NameDescription
Public methodBindToName
When OmitAssemblyNameOnSerialize is , suppresses the assembly name on serialization. Otherwise, returns  for both assembly and type names, indicating that the original names should be used.
(Overrides SerializationBinderBindToName(Type, String, String).)
Public methodBindToType
Retrieves a type by its assemblyName and typeName.
(Overrides SerializationBinderBindToType(String, String).)
Top
Extension Methods

  NameDescription
Public Extension MethodConvert(Type, CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired targetType.
See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example.
(Defined by ObjectExtensions.)
Public Extension MethodCode exampleConvertTTarget(CultureInfo)Overloaded.
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)
Public Extension MethodIn (Defined by ObjectExtensions.)
Public Extension MethodTryConvert(Type, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvert(Type, CultureInfo, Object)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Public Extension MethodTryConvertTTarget(CultureInfo, TTarget)Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example.
(Defined by ObjectExtensions.)
Top
Remarks

Security note Security Note

If a deserialization stream may come from an untrusted source, then make sure to set the SafeMode property to  to prevent loading assemblies when resolving types.

See the security notes at the Remarks section of the BinarySerializationFormatter class for more details.

Note Note
This binder does not use exact type mapping just tries to resolve type information automatically. To customize type mapping or use a custom resolve logic you can use the ForwardedTypesSerializationBinder or CustomSerializationBinder classes, respectively.

The WeakAssemblySerializationBinder class allows resolving type information by weak assembly identity, or by completely ignoring assembly information (if IgnoreAssemblyNameOnResolve property is .)

It also makes possible to prevent loading assembles during deserialization if the SafeMode property is .

Tip Tip
You can make even a BinaryFormatter safe by assigning a WeakAssemblySerializationBinder with SafeMode =  to its Binder property so it cannot resolve any type whose assembly is not already loaded.

If WeakAssemblySerializationBinder is used on serialization, then it can omit assembly information from the serialization stream if the OmitAssemblyNameOnSerialize property is .

See Also

Reference