Error “Invalid at the top level of the document” creating a Visual Studio 2012 Wizard

被刻印的时光 ゝ 提交于 2020-01-16 04:50:06

问题


I am trying to create a New Item Wizard for Visual Studio 2012. This would be a wizard to create several C++ files and add them to the project. I have created a similar wizard for VS 2005. I'm trying to create this using the IDTWizard interface. I followed this walkthrough: http://msdn.microsoft.com/en-us/library/7k3w6w59(v=vs.110).aspx

When i try to use the wizard, I get an error message that says "invalid at the top level of the document". My dll shows up as a registered COM object when I look through the data displayed by oleview.exe. What am I doing wrong? Should I be doign this the same way I created my VS2005 wizard, using html/javascript? My code is below:

Wizard.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using EnvDTE80;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SystemsModuleWizard
{
    [ComVisible(true)]
    [Guid("FE7DC545-30DC-445B-8130-897C5F3114EC"), ProgId("SystemsModuleWizard.WizardClass")]

    public class WizardClass : IDTWizard
    {
        public void Execute(object Application,
            int hwndOwner, ref object[] contextParams,
            ref object[] customParams,
            ref EnvDTE.wizardResult retval) 
        {
            MessageBox.Show("The wizard is running");

        }
    }
}

AssemblyInfo.cs:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SystemsModuleWizard")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SystemsModuleWizard")]
[assembly: AssemblyCopyright("Copyright ©  2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ab29b7df-32c4-4dca-ade4-a31f687b9331")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

回答1:


I notice your Execute implementation is:

public void Execute(object Application,
        int hwndOwner, ref object[] contextParams,
        ref object[] customParams,
        ref EnvDTE.wizardResult retval) 
    {
        MessageBox.Show("The wizard is running");

    }

But according to this MSDN page, retval is an out parameter, not a ref parameter:

void Execute(
    Object Application,
    int hwndOwner,
    ref Object[] ContextParams,
    ref Object[] CustomParams,
    out wizardResult retval
)

The walkthrough you linked to certainly gives it as ref, but perhaps that's an error. I don't see how both can work--the memory allocation and marshalling would be different. Give it a try. Hope this helps.




回答2:


I was intrigued by this, so I knocked up a quick wizard following the steps in your linked walkthrough. But it worked fine:

(And it turns out the question of ref or out param doesn't arise, as it won't even compile with out. So that other MSDN page is plain wrong to give it as out.)

So I set out to see how I could break it.

Here's how: introduce an error into the .vsz file, . For example, if your file contains the lines

VSWIZARD 7.0
Wizard=MyNewWizard.Class1
Param=First Item
Param=Second Item

mis-spell the classname in the second line:

Wizard=ThyNewWizard.Class1

When I did this, it obligingly displayed your error message:

Since you've checked that your class is registered with COM, it therefore looks likely to be a typo etc in your .vsz file.



来源:https://stackoverflow.com/questions/24188932/error-invalid-at-the-top-level-of-the-document-creating-a-visual-studio-2012-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!