Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected override void BeginProcessing()
WriteObject(_newObject);
return;
}
else if (type.GetTypeInfo().IsValueType)
else if (type.IsValueType)
{
// This is for default parameterless struct ctor which is not returned by
// Type.GetConstructor(System.Type.EmptyTypes).
Expand Down Expand Up @@ -351,12 +351,12 @@ protected override void BeginProcessing()
#if !UNIX
#region Com

private object SafeCreateInstance(Type t, object[] args)
private object SafeCreateInstance(Type t)
{
object result = null;
try
{
result = Activator.CreateInstance(t, args);
result = Activator.CreateInstance(t);
}
// Does not catch InvalidComObjectException because ComObject is obtained from GetTypeFromProgID
catch (ArgumentException e)
Expand Down Expand Up @@ -430,13 +430,10 @@ private void STAComCreateThreadProc(object createstruct)
ComCreateInfo info = (ComCreateInfo)createstruct;
try
{
Type type = null;
PSArgumentException mshArgE = null;

type = Type.GetTypeFromCLSID(_comObjectClsId);
Type type = Type.GetTypeFromCLSID(_comObjectClsId);
if (type == null)
{
mshArgE = PSTraceSource.NewArgumentException(
PSArgumentException mshArgE = PSTraceSource.NewArgumentException(
"ComObject",
NewObjectStrings.CannotLoadComObjectType,
ComObject);
Expand All @@ -446,7 +443,7 @@ private void STAComCreateThreadProc(object createstruct)
return;
}

info.objectCreated = SafeCreateInstance(type, ArgumentList);
info.objectCreated = SafeCreateInstance(type);
info.success = true;
}
catch (Exception e)
Expand All @@ -458,20 +455,25 @@ private void STAComCreateThreadProc(object createstruct)

private object CreateComObject()
{
Type type = null;
PSArgumentException mshArgE = null;

try
{
type = Marshal.GetTypeFromCLSID(_comObjectClsId);
Type type = Marshal.GetTypeFromCLSID(_comObjectClsId);
if (type == null)
{
mshArgE = PSTraceSource.NewArgumentException("ComObject", NewObjectStrings.CannotLoadComObjectType, ComObject);
PSArgumentException mshArgE = PSTraceSource.NewArgumentException(
"ComObject",
NewObjectStrings.CannotLoadComObjectType,
ComObject);

ThrowTerminatingError(
new ErrorRecord(mshArgE, "CannotLoadComObjectType", ErrorCategory.InvalidType, null));
new ErrorRecord(
mshArgE,
"CannotLoadComObjectType",
ErrorCategory.InvalidType,
targetObject: null));
}

return SafeCreateInstance(type, ArgumentList);
return SafeCreateInstance(type);
}
catch (COMException e)
{
Expand Down