My first VB.Net add-in will not load

My first VB.Net add-in will not load

Anonymous
Not applicable
520 Views
4 Replies
Message 1 of 5

My first VB.Net add-in will not load

Anonymous
Not applicable

I'm just starting out with Visual Basic 2008
Express.  I've read Brian Ekins' white paper titled "Taking the Step from
VBA Macros to Add-Ins" top to bottom and to the best of my knowledge I've
followed each and every step outlined there exactly.  My add-in compiles
and registers with no errors nor warnings.  It appears
in Inventor's list of add-ins, but is Unloaded and will not Load. 
This is driving me absolutely crazy, so can someone PLEASE tell me what the
hell I'm doing wrong?

 

Below is the code that appears in the
CenterAlignAddInServer.vb class.  Note that "objInventor" is declared as a
global variable in a module named Global.vb.

 


Imports


face=Verdana color=#000000> Inventor


Imports


face=Verdana color=#000000>
System.Runtime.InteropServices


Imports


face=Verdana color=#000000> Microsoft.Win32


Namespace


face=Verdana color=#000000> CenterAlign


<ProgIdAttribute(


face=Verdana color=#000000
size=2>"CenterAlign.CenterAlignAddInServer"

face=Verdana color=#000000>), _


GuidAttribute(


face=Verdana color=#000000
size=2>"20a8f692-d9cd-4747-bdc7-5d2233da828f"

face=Verdana color=#000000>)> _


Public
size=2>
Class

face=Verdana color=#000000> CenterAlignAddInServer


Implements
size=2>
Inventor.ApplicationAddInServer



size=2>Private
WithEvents
size=2> objCenterAlignButton
As

size=2> Inventor.ButtonDefinition


Private Declare Function
SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Int32, ByVal
hWndNewParent As Int32) As Int32


#Region


face=Verdana>
size=2>"ApplicationAddInServer Members"


Public
size=2>
Sub Activate(
size=2>ByVal
addInSiteObject
size=2>As
Inventor.ApplicationAddInSite,
size=2>ByVal
firstTime As
size=2>
Boolean)
size=2>Implements

color=#000000> Inventor.ApplicationAddInServer.Activate


Dim
size=2> strAddInGUID
As
size=2>String


Dim
size=2> objCommandBar
As

size=2> Inventor.CommandBar


' This method is called
by Inventor when it loads the AddIn.


' The AddInSiteObject
provides access to the Inventor Application object.


size=2>

' The FirstTime flag
indicates if the AddIn is loaded for the first time.


size=2>

' Initialize AddIn
members.


objInventor =
addInSiteObject.Application


strAddInGUID =


face=Verdana>"{" &
CType
size=2>(System.Attribute.GetCustomAttribute(

size=2>GetType
(CenterAlignAddInServer),
size=2>GetType
(GuidAttribute)), GuidAttribute).Value &
"}"


objCenterAlignButton =
objInventor.CommandManager.ControlDefinitions.AddButtonDefinition(


face=Verdana>"CenterAlign",
"CenterAlignButton",
CommandTypesEnum.kEditMaskCmdType, strAddInGUID,

size=2>"CenterAlign"
, "Aligns parallel
centerlines"

color=#000000>)


If
size=2> firstTime
Then


objCommandBar =
objInventor.UserInterfaceManager.CommandBars(


color=#000000 size=2>"DLxDrawingAnnotationPanelCmdBar"

face=Verdana color=#000000>)



color=#000000>objCommandBar.Controls.AddButton(objCenterAlignButton)


End
size=2>
If


objCommandBar =


size=2>Nothing


End
size=2>
Sub


Public
size=2>
Sub Deactivate()
size=2>Implements

Inventor.ApplicationAddInServer.Deactivate



color=#000000>Marshal.ReleaseComObject(objInventor)


objInventor =


size=2>Nothing


objCenterAlignButton =


size=2>Nothing



color=#000000>System.GC.WaitForPendingFinalizers()


System.GC.Collect()


End
size=2>
Sub


Public
size=2>
ReadOnly
size=2>Property
Automation()
size=2>As
Object
Implements

face=Verdana color=#000000>
Inventor.ApplicationAddInServer.Automation


' This property is
provided to allow the AddIn to expose an API


' of its own to other
programs. Typically, this would be done by


' implementing the
AddIn's API interface in a class and returning


' that class object
through this property.



color=#000000>Get


Return
size=2>
Nothing


End
size=2>
Get


End
size=2>
Property


Public
size=2>
Sub ExecuteCommand(
size=2>ByVal
commandID As
size=2>
Integer)
size=2>Implements

color=#000000> Inventor.ApplicationAddInServer.ExecuteCommand


' Note:this method is
now obsolete, you should use the


' ControlDefinition
functionality for implementing commands.


End
size=2>

color=#000000>Sub


#End


color=#000000 size=2>

color=#000000>Region


#Region


face=Verdana> "COM
Registration"


' Registers this class
as an AddIn for Inventor.


' This function is
called when the assembly is registered for COM.


<ComRegisterFunctionAttribute()>
_


Public
size=2>
Shared
size=2>Sub
Register(ByVal
size=2> t
As

face=Verdana color=#000000> Type)


Dim
size=2> clssRoot
As

face=Verdana color=#000000> RegistryKey = Registry.ClassesRoot


Dim
size=2> clsid
As RegistryKey =
Nothing


Dim
size=2> subKey
As RegistryKey =
Nothing



color=#000000>Try


clsid =
clssRoot.CreateSubKey(


size=2>"CLSID\"
+
AddInGuid(t))


clsid.SetValue(


face=Verdana>Nothing,
"CenterAlign"

face=Verdana color=#000000>)


subKey =
clsid.CreateSubKey(


size=2>"Implemented
Categories\{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}"

face=Verdana color=#000000>)


subKey.Close()


subKey =
clsid.CreateSubKey(


size=2>"Settings"

color=#000000>)


subKey.SetValue(


face=Verdana>"AddInType",
"Standard"

face=Verdana color=#000000>)


subKey.SetValue(


face=Verdana>"LoadOnStartUp"
size=2>,
"1"

face=Verdana color=#000000>)



color=#000000>'subKey.SetValue("SupportedSoftwareVersionLessThan",
"")


subKey.SetValue(


face=Verdana>
size=2>"SupportedSoftwareVersionGreaterThan"
,
size=2>"12.."

color=#000000>)



color=#000000>'subKey.SetValue("SupportedSoftwareVersionEqualTo",
"")



color=#000000>'subKey.SetValue("SupportedSoftwareVersionNotEqualTo",
"")



color=#000000>'subKey.SetValue("Hidden", "0")



color=#000000>'subKey.SetValue("UserUnloadable", "1")


size=2>

subKey.SetValue(


face=Verdana color=#000000 size=2>"Version"

face=Verdana color=#000000>, 0)


subKey.Close()


subKey =
clsid.CreateSubKey(


size=2>"Description"

color=#000000>)


subKey.SetValue(


face=Verdana>Nothing,
"CenterAlign"

face=Verdana color=#000000>)


Catch
size=2> ex
As

face=Verdana color=#000000> Exception



color=#000000>System.Diagnostics.Trace.Assert(


color=#000000 size=2>False

color=#000000>)



color=#000000>Finally


If
size=2>
Not subKey
size=2>Is
Nothing
Then

color=#000000> subKey.Close()


If
size=2>
Not clsid
size=2>Is
Nothing
Then

color=#000000> clsid.Close()


If
size=2>
Not clssRoot
size=2>Is
Nothing
Then

color=#000000> clssRoot.Close()


End
size=2>
Try


End
size=2>
Sub


' Unregisters this class
as an AddIn for Inventor.


' This function is
called when the assembly is unregistered.


<ComUnregisterFunctionAttribute()>
_


Public
size=2>
Shared
size=2>Sub
Unregister(ByVal
size=2> t
As

face=Verdana color=#000000> Type)


Dim
size=2> clssRoot
As

face=Verdana color=#000000> RegistryKey = Registry.ClassesRoot


Dim
size=2> clsid
As RegistryKey =
Nothing



color=#000000>Try


clssRoot =
Microsoft.Win32.Registry.ClassesRoot


clsid =
clssRoot.OpenSubKey(


size=2>"CLSID\"
+ AddInGuid(t),
size=2>True

color=#000000>)


clsid.SetValue(


face=Verdana>Nothing,
""

color=#000000>)


clsid.DeleteSubKeyTree(


face=Verdana color=#000000 size=2>"Implemented
Categories\{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}"

face=Verdana color=#000000>)


clsid.DeleteSubKeyTree(


face=Verdana color=#000000 size=2>"Settings"

face=Verdana color=#000000>)


clsid.DeleteSubKeyTree(


face=Verdana color=#000000 size=2>"Description"

face=Verdana color=#000000>)



color=#000000>Catch



color=#000000>Finally


If
size=2>
Not clsid
size=2>Is
Nothing
Then

color=#000000> clsid.Close()


If
size=2>
Not clssRoot
size=2>Is
Nothing
Then

color=#000000> clssRoot.Close()


End
size=2>
Try


End
size=2>
Sub


' This property uses
reflection to get the value for the GuidAttribute attached to the
class.


Public
size=2>
Shared
size=2>ReadOnly
Property
size=2> AddInGuid(
ByVal t
size=2>As
Type) As
String



color=#000000>Get


Dim
size=2> guid
As
size=2>String
=
size=2>""



color=#000000>Try


Dim
size=2> customAttributes()
As
Object =
t.GetCustomAttributes(
GetType
size=2>(GuidAttribute),
False

size=2>)


Dim
size=2> guidAttribute
As GuidAttribute =
CType

color=#000000>(customAttributes(0), GuidAttribute)


guid =


face=Verdana>"{" +
guidAttribute.Value.ToString() +

size=2>"}"



color=#000000>Finally


AddInGuid = guid


End
size=2>
Try


End
size=2>
Get


End
size=2>

color=#000000>Property


#End


color=#000000>
size=2>Region



size=2>Private
Sub
objCenterAlignButton_OnExecute(
ByVal
Context
As Inventor.NameValueMap)
Handles

color=#000000> objCenterAlignButton.OnExecute


Dim
size=2> objCenterAlignDialog
As
New

color=#000000> CenterAlignDialog



color=#000000>SetParent(objCenterAlignDialog.Handle.ToInt32,
objInventor.MainFrameHWND)


objCenterAlignDialog.Show()


End
size=2>
Sub


End
size=2>

color=#000000>Class


End


color=#000000>
size=2>Namespace

0 Likes
521 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Well, I found the problem and apparently it's an
old one.

 

The problem was the location of the
.dll.  I moved it from its original location (inside My Documents) to a
folder beneath Inventor's \bin folder and viola, it works.  I thought I
remembered reading that this problem was resolved a long time ago?






brian r.
iwaskewycz


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">inventor
specialist

0 Likes
Message 3 of 5

Anonymous
Not applicable

This should no longer be an issue. Is this a test
on your development machine, or are you testing the dll on another machine? If
on another machine, did you register the add-in on that machine using the
/codebase switch?

 

32 or 64 bit O/S's?

 

In the properties page for the project, is
"Register form COM interop" checked? (It should be if you used the Inventor
Add-in project template.) Can you debug the add-in?

 

 

 

 

 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Well, I found the problem and apparently it's
an old one.

 

The problem was the location of the
.dll.  I moved it from its original location (inside My Documents) to a
folder beneath Inventor's \bin folder and viola, it works.  I thought I
remembered reading that this problem was resolved a long time
ago?






brian
r. iwaskewycz


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">inventor
specialist


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">

style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">
title="http://www.corefurnace.com/ CTRL + Click to follow link"
href="http://www.corefurnace.c...

0 Likes
Message 4 of 5

Anonymous
Not applicable

It's a test on a development
machine.

 

64-bit OS.

 

I don't see "Register form COM interop" anywhere
(maybe because I'm using VB2008 Express?).

 

No, I CANNOT debug the add-in (keep seeing "No
symbols have been loaded for this document.")  Starting to anger
me.






brian r.
iwaskewycz


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">inventor
specialist


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">core furnace
systems
0 Likes
Message 5 of 5

Anonymous
Not applicable

Try the following:

 

Debugging with VS Express Editions (See Brian's
reply)

 


 


Registering 64 bit add-ins (I assume you will need to do this on your
dev machine as well if you want it to run outside the dev environment)

 


 

Get your company to spring for the Standard edition
of Visual Studio, worth the few bucks.

 

HTH

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


It's a test on a development
machine.

 

64-bit OS.

 

I don't see "Register form COM interop"
anywhere (maybe because I'm using VB2008 Express?).

 

No, I CANNOT debug the add-in (keep seeing "No
symbols have been loaded for this document.")  Starting to anger
me.






brian
r. iwaskewycz


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">inventor
specialist


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">

style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">core furnace
systems
0 Likes