private static object CreateInstanceOfType(Type type) {
object instancedObject = null;
Exception instanceException = null;
try {
instancedObject = SecurityUtils.SecureCreateInstance(type);
}
catch (TargetInvocationException ex) {
instanceException = ex; // Default ctor threw an exception
}
catch (MethodAccessException ex) {
instanceException = ex; // Default ctor was not public
}
catch (MissingMethodException ex) {
instanceException = ex; // No default ctor defined
}
if (instanceException != null) {
throw new NotSupportedException(SR.GetString(SR.BindingSourceInstanceError), instanceException);
}
return instancedObject;
}