Property Page is not loaded on Vista

  • Thread starter Thread starter Dhananjay
  • Start date Start date
D

Dhananjay

Hi All,
I have developed one COM-Addin in vb 2005 / VSTO / Office 2007. I have
added one property page to the options page. My addin loads perfectly
with the correct option page, on any platform for many machines. i.e.
my addin works for Vista, xP, 2003 server etc. with office 2007
installed on it. My property page is also loading perfectly. But on
some machine with Office 2007 / Vista, I can not click on my property
page. I get error - "Cannot display "Custom" page. This page will
remain visible, but is not available".
To display property page I have included one form which Inherits from
System.Windows.Forms.UserControl & Implements
Microsoft.Office.Interop.Outlook.PropertyPage. & in my
Application_OptionPagesAdd event, I added the line
Pages.Add("Custom.PropPage", "Custom Title"). Also in my trace file I
can see the trace before & after "Pages.add ..." line & also
proppage_load event's trace. But when someone clicks on the tab, he is
greeted with this error & also my trace file contains
Application_optionPagesAdd trace & doesn't contain PropPage_Load
events trace statements at all.
As I mentioned before, my addin is working fine on all machines with
platforms XP, 2k3 , Vista etc, but on some machines (Office 2007 with
Vista), only I am getting this error.

So what should I check on those machines specifically?

Thanks in advance,
Dhananjay
 
Usually when that error occurs it means either the property page control
isn't registered for OCX controls or there was an error in that page. Are
you sure that all controls you used that might need to be deployed to the
target systems are actually deployed and registered on those computers where
the property page display fails?
 
Hi Ken,
Thanks for your valuable reply.
First of all, I have not added any external ocx for property page( If
my class inherits from UserControl & implements PropertyPage and then
it is said to be ocx, i don't know abt it.). Further I have not used
any other external control on the propertypage. my code snippet for
property page load is as follows -

AddTrace("Property page is loading ...")
Dim myType As Type = GetType(System.Type)
Dim assembly As String =
System.Text.RegularExpressions.Regex.Replace(myType.Assembly.CodeBase,
"mscorlib.dll", "System.Windows.Forms.dll")
assembly =
System.Text.RegularExpressions.Regex.Replace(assembly, "file:///", "")
assembly =
System.Reflection.AssemblyName.GetAssemblyName(assembly).FullName
Dim unmanaged As Type =
Type.GetType(System.Reflection.Assembly.CreateQualifiedName(assembly,
"System.Windows.Forms.UnsafeNativeMethods"))
Dim oleObj As Type = unmanaged.GetNestedType("IOleObject")
Dim mi As System.Reflection.MethodInfo =
oleObj.GetMethod("GetClientSite")
Dim myprop As Object = mi.Invoke(Me, Nothing)
myPropSite = TryCast(myprop,
Microsoft.Office.Interop.Outlook.PropertyPageSite)
If myPropSite Is Nothing Then
AddTrace("Error - Site not Loaded")
MsgBox("Site not loaded")
GoTo AtEnd
Else
AddTrace("Site Loaded successfully")
blnDirty = False
End If
AddTrace("Option page loaded")

The all code above I got from one site (I don't remember the site
name). But if this code is having prob, pl guide me.

Thanks again,
Dhananjay
 
With managed code you don't have to have a separate OCX for the property
page, an OCX is an ActiveX control, that's how it's done in unmanaged code.
However, if you aren't using any special controls on your property page user
control (like a 3rd party grid control for example) and not compiling a
separate unmanaged OCX then those usual causes don't apply obviously.

If the code you're using works on some target computers (other than the dev
machine and any others with Visual Studio installed) then it's down to
what's different on the computers where it works and where it doesn't work.
I'd be looking at the Framework security setup on the affected machines as
opposed to where it works, any dependencies in the project to make sure they
exist or are deployed and possibly adding lots of logging code to see
exactly which code line is firing the exception.

Another thing you can try is one of the sample projects (for Outlook 2007)
on my Web site at http://www.slovaktech.com/outlook_2007_templates.htm. I
have totally basic property pages in those projects that you can test and
see if they work on the problem computers if they're running Outlook 2007.
The property page code I used isn't specific to Outlook 2007, so you can use
something like what I have even for Outlook 2003 as a test if you put it in
an Outlook 2003 COM addin project.

The code I use to get the Site in the page startup is very similar to the
code you're using, here's what I use:

Imports Outlook = Microsoft.Office.Interop.Outlook
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.ComponentModel

Public Class ToolsOptionsPP
Implements Outlook.PropertyPage

Private m_dirty As Boolean
Private m_site As Outlook.PropertyPageSite

Private m_caption As String

Public Sub Apply() Implements
Microsoft.Office.Interop.Outlook.PropertyPage.Apply
If m_dirty Then
'do something to save properties

'clear the dirty flag
m_dirty = False
End If
End Sub

Public ReadOnly Property Dirty() As Boolean Implements
Microsoft.Office.Interop.Outlook.PropertyPage.Dirty
Get
Dirty = m_dirty
End Get
End Property

Public Sub GetPageInfo(ByRef HelpFile As String, ByRef HelpContext As
Integer) Implements
Microsoft.Office.Interop.Outlook.PropertyPage.GetPageInfo
'show help file here
End Sub

Private Sub ToolsOptionsPP_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
' HACK: uses reflection to call a private unsafe method!
Dim userControlType As Type = GetType(Windows.Forms.UserControl)

Dim oleObjectType As Type =
userControlType.Assembly.GetType("System.Windows.Forms.UnsafeNativeMethods+IOleObject")

Dim method As MethodInfo = oleObjectType.GetMethod("GetClientSite")

m_site = TryCast(method.Invoke(Me, Nothing),
Outlook.PropertyPageSite)

End Sub

Private Sub SetDirty()
m_dirty = True

If m_site IsNot Nothing Then
m_site.OnStatusChange()
End If
End Sub

Protected Overrides Sub Finalize()
m_site = Nothing

MyBase.Finalize()
End Sub

<DispId(-518)> _
Public Property Caption() As String
' Return the OptionsPage Caption here.
Get
Return m_caption
End Get

Set(ByVal value As String)
m_caption = value
End Set
End Property
End Class
 
Hi Ken,
Thanks for your reply.
I downloaded your sample project from http://www.slovaktech.com/outlook_2007_templates.htm
viz. "VSTO 2005 SE VB.NET Addin Project". Your addin shows me one menu
bar & in that, one test button. Also I can see your tab in Tools ->
Options page. Hence while debugging control goes to
Application_OptionsPagesAdd
, but now when I click on ur tab, it doesn't give me any error message
or control doesn't go to "ToolsOptionsPP_Load" :-( . This is my
developement machine with Win XP, Office 2k7 , Visual Studio 2005.
What may be the problem with my machine?
Thanks for ur patience!

Dhananajy
 
Hi Ken,
Further I need some clarifications from you.
1> Framework security setup : What is it? How can I check it? Can it
be fixed by installing .net framework again?
2> Dependencies in the project to make sure they exist or are
deployed : Actually I am confused with this part. I have checked my
addin on clean Vista machine without any development platform on it.
It worked for me. For that , I used totally formatted disk to install
Vista & office 2007. So my thinking is that I am deploying all the
necessary files to client machine.
3> Possibly adding lots of logging code : I have added trace after
each line. But as I said before, I can see the trace for
Applications_PagesAdd only & not a single line from Page_Load method.

Thanks again!
Dhananjay
 
Framework security should be set by the installer package or manually using
the Framework configuration utility. It's not set by installing or
reinstalling the Framework. For a VSTO addin you need to have full trust set
up for your addin assemblies. That's usually done with the SetSecurity
project as detailed at
http://msdn2.microsoft.com/en-us/library/bb332051.aspx. Those articles also
have information about deploying on Vista, and there's more information
about deployments at http://www.outlookcode.com/article.aspx?ID=42. I'd
suggest carefully studying all the information available at those locations.

If the addin sample from my Web site is working for you then it's a matter
of comparing your code and deployment with the sample and seeing what's
different. I can't do that for you.

If the property page is displaying on some systems and not on others then
you have to try and find out what's different. Again that's detective work
you'll have to do.
 
Back
Top