Call to EnvDTE.TextSelection.FindPattern from PowerShell fails with type mismatch

1

I'm building a custom scaffolder to use with MvcScaffolding. Trying to automate adding code to the beginning of a method, I came up with the following code:

$codeElement = Get-ProjectType "MyType"

foreach ($member in $codeElement.Members)
{
    if ($member.Name -eq "CreateMappings")
    {
        $editPoint = $member.StartPoint.CreateEditPoint()

        # here's where it's crashing
        $editPoint.FindPattern("\{")

        $editPoint.Insert("text")
    }
}

When I run my custom scaffolder, FindPattern fails with

Exception calling "FindPattern" with "1" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"

At Path\File.ps1:62 char:26
+             $editPoint.FindPattern <<<< ("\{")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

As opposed to this macro, which runs just fine:

Sub macro()
    Dim objTD As TextDocument = DTE.ActiveDocument.Object("TextDocument")
    Dim editPoint As EditPoint = objTD.StartPoint.CreateEditPoint()
    If (editPoint.FindPattern("\{", vsFindOptions.vsFindOptionsRegularExpression)) Then
        editPoint.CharRight()
        editPoint.Insert("text")
    End If
End Sub

What am I doing wrong?

powershell
com
envdte
asp.net-mvc-scaffolding
asked on Stack Overflow Apr 3, 2012 by Călin Darie • edited Apr 3, 2012 by Călin Darie

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0