Visual Studio Development Bookmark and Share   
 index > Visual Studio Extensibility > adding Interface using CodeNamespace get error in VB.Net but work C#.Net
 

adding Interface using CodeNamespace get error in VB.Net but work C#.Net

Hi All,

I have one Addin which contain dialog for making some interface which inherit own interface(MyPackage.IFG)
dialog read or write interface. I have used CodeElements and using CodeNamespace, i am adding add interface (AddInterface) like

inter = codeNamespace.AddInterface(fG.Name, position, fG.ParentInterfaceList.ToArray(),
EnvDTE.vsCMAccess.vsCMAccessPublic);

here =>
fG.ParentInterfaceList is ArrayList of string ("MyPackage.IFG") or ("FG1","FG2")
position = -1

This all work fine in C#.Net but same is giving error in VB.Net
and eror is
System.ArgumentException] = {"Value does not fall within the expected range."}

I think this is problem of passing argument for "Bases" (inherit base interfaces) here fG.ParentInterfaceList.ToArray()

but same is working for C#.Net, cant understand what's actually missing..

Waiting for reply, below you can find sample file on which read/write inferface using Addin->dialog.

Thanks,
Nik


C#.net
==========
using MyPackage;

namespace BusinessObjects
{
public interface XYZ : MyPackage.IFG
{
}
}
==========

VB.Net
==========
Imports MyPackage

Namespace Step3_BusinessObjects

End Namespace
==========
Niku  Tuesday, January 13, 2009 4:48 AM
Yes, the problem is the Bases parameter. You have to pass an array of strings to work in VB.NET:

Sub f1()

Dim codeNamespace = CType(DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements.Item(1), CodeNamespace)

Dim bases As Object = New String() {"IAsyncResult"}

codeNamespace.AddInterface("MyInterface", -1, bases, vsCMAccess.vsCMAccessPublic)

End Sub

MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about VS extensibility: http://msmvps.com/blogs/carlosq/
Carlos Quintero - MVP  Tuesday, January 13, 2009 8:32 AM
Yes, the problem is the Bases parameter. You have to pass an array of strings to work in VB.NET:

Sub f1()

Dim codeNamespace = CType(DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements.Item(1), CodeNamespace)

Dim bases As Object = New String() {"IAsyncResult"}

codeNamespace.AddInterface("MyInterface", -1, bases, vsCMAccess.vsCMAccessPublic)

End Sub

MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about VS extensibility: http://msmvps.com/blogs/carlosq/
Carlos Quintero - MVP  Tuesday, January 13, 2009 8:32 AM

You can use google to search for other answers

Custom Search

More Threads

• How to Gracefully handle ServiceCreatorCallback errors?
• How to propagate change of property value to VS (e.g. editor and property browser)
• Recursion in a Template
• Close IDE editor window via the "Close" ("x") button.
• How Do I Add a Tools/Options Page to a VS2003 Package
• How to specify a default location for projects generated by a template
• add node into treeview by event
• Macro to switch on XML documentation?
• Icon Editor
• ErrorList Window: How to fill in File and Project fields ?