system.invalidcastexception in SetAddInInfo

Hi.

 

 

I am a begginer and iwant to create a simple add-in, but i have unclear to me exeption in SetAddInInfo method:

system.invalidcastexception unable to cast object of type 'system.int32' to type 'system.string'

 

Here is a part of code:

public void OnConnectToEnvironment(string EnvCatID, object pEnvironmentDispatch, bool bFirstTime)

{

try

{

MessageBox.Show("Onconnect");

string[] commandNames = new string[2];

commandNames[0] = "XYZ VB addin sample command 1\nVB Command1\nSample 1\nSample command 1";

commandNames[1] = "XYZ VB addin sample command 2\nVB Command1\nSample 2\nSample command 2";

 

int[] commandIDs = new int[2];

commandIDs[0] = 101;

commandIDs[1] = 102;

 

Array cmdid = commandIDs;

Array cmdname = commandNames;

 

//on every entry to enviroment (part/assembly/etc..) this func is called..

m_addin.SetAddInInfo(Marshal.GetHINSTANCE(this.GetType().Module).ToInt32(), EnvCatID, "ManagedMenu", 101, 102,-1, -1, 2, ref cmdid, ref cmdname);

 

if (bFirstTime)

{

SolidEdgeFramework.Environment env = (SolidEdgeFramework.Environment)pEnvironmentDispatch;

env.CommandBars.Add("ManagedMenu", SolidEdgeFramework.SeBarPosition.seBarRight, true, true);

 

m_addin.AddCommandBarButton(EnvCatID, "ManagedMenu", 101);

m_addin.AddCommandBarButton(EnvCatID, "ManagedMenu", 102);

}

 

m_addin.SetAddInInfo(Marshal.GetHINSTANCE(this.GetType().Module).ToInt32(), EnvCatID, "ManagedMenu", 1, 2, 1, 2, commandIDs.Length, ref cmdid, ref cmdname);

}

catch (Exception e)

{

MessageBox.Show(e.ToString());

}

 

}

Plz help! Thanks for all guesses!

 

Posted by: Walker
Post date: 5/28/2012 8:02:30 AM

1 REPLY

Re: system.invalidcastexception in SetAddInInfo

Which call throws the exception? I see to calls to SetAddinInfo.

 

By the way, to support 64 bit Solid Edge and 32 bit Solid Edge, don't call SetAddinInfo. Call SetAddinInfoEx.

 

Do something like this (taken from the vb.net sample in the solid edge sdk):

 

Dim pAddinEx As SolidEdgeFramework.ISEAddInEx

 

pAddinEx = pAddin

 

If (LCase(EnvCatID) = LCase(CATID_SEApplication)) Then

ApplicationCommandIDs(0) = 1

ApplicationCommandIDs(1) = 2

 

If Not pAddinEx Is Nothing Then

pAddinEx.SetAddInInfoEx(ResFilename, EnvCatID, CategoryName, CmdImageMediumColor, CmdImageLargeColor, CmdImageMediumBlackAndWhite, CmdImageLargeBlackAndWhite, 2, CommandNames, ApplicationCommandIDs)

Else

pAddin.SetAddInInfo(ResHandle, EnvCatID, CategoryName, CmdImageMediumColor, CmdImageLargeColor, CmdImageMediumBlackAndWhite, CmdImageLargeBlackAndWhite, 2, CommandNames, ApplicationCommandIDs)

End If

End If

 

' add the commands in part

If (LCase(EnvCatID) = LCase(CATID_SEPart)) Then

PartCommandIDs(0) = 1

PartCommandIDs(1) = 2

 

If Not pAddinEx Is Nothing Then

pAddinEx.SetAddInInfoEx(ResFilename, EnvCatID, CategoryName, CmdImageMediumColor, CmdImageLargeColor, CmdImageMediumBlackAndWhite, CmdImageLargeBlackAndWhite, 2, CommandNames, PartCommandIDs)

Else

pAddin.SetAddInInfo(ResHandle, EnvCatID, CategoryName, CmdImageMediumColor, CmdImageLargeColor, CmdImageMediumBlackAndWhite, CmdImageLargeBlackAndWhite, 2, CommandNames, PartCommandIDs)

End If

End If

 

Posted by: R.D. Holland
Post date: 6/1/2012 4:55:04 PM