PropertyGrid not working right when called from a Word Add-In

D

David Thielen

Hi;

Ok, I have a small sample up at
http://www.windwardreports.com/WordPropertyGridTest.zip. The WordPropGrid
sample comes from
http://support.microsoft.com/default.aspx?scid=kb;en-us;302901 which I think
is the smallest Word Add-In sample MS has.

Two notes on WordPropGrid:
1) You may have to change the reference to _office.dll to Office.dll
(proplem on my system where it finds Office.dll in two places - so I had to
rename the one).
2) Build it to get it in the registry so Word will see it. If that is not
sufficient, run the setup program in the solution and then build again.

When you run it, click the menu bar and it will bring up the property grid.
Expand coll, [0] and you will see Data & Title greyed, not expandable, and
not editable.

Now run PropGridTest (also in the zip file). The files with the same names
are identical - it is all the same code. But when running it Data & Title are
expandable and their component pieces are editable.

So, what is the problem?

And if it's a bug in Word/.NET, please please please give me a work-around.
I need this functionality and since we ship this to customers, a hot-fix
won't work because they aren't going to install a hot-fix just to use our
software.
 
W

Wei-Dong XU [MSFT]

Hi Dave,

Currently we are finding one support engineer for you on this issue. We
will update in this thread as soon as possbile.

Thanks for your understanding!

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi

So far I am researching the issue.
Based on my test, now you may use the code as below to workaround the issue.
[TypeConverter(typeof(ExpandableObjectConverter))] // Use the
ExpandableObjectConverter directly on ChartColumnSelect
// [Editor(typeof(TestDialogEditor),typeof(UITypeEditor))]
public class ChartColumnSelect
{

You may have a try.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

The problem with using ExpandableObjectConverter is I need the override
capabilities. Not just the ConvertTo but even more the methods for parsing
and entered string.

Definitely a weird bug though???
 
P

Peter Huang [MSFT]

Hi

Based on my further test, we need to put the Addin into GAC will make the
propertygrid work.
I think that is why the ExpandableObjectConverter itself will work, because
its host dll is in the GAC.
You may have a try.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

The problem with that approach is that my converter is part of my add-in and
MS says to NOT put an add-in in the GAC.

Even worse, the Office 2000 & 2002 PIAs are also not supposed to go in the
GAC and my code needs those under Word 2000 & Word 2002.

So... What should I do? Is there another work-around? Or should I put my
add-in and the PIAs in the GAC?

Also, the non add-in sample does not have the converter in the GAC and it
works ok.

Please advise.
 
P

Peter Huang [MSFT]

Hi

I think you may try to extract the propertygrid code from Addin and build
it as a single strongnamed dll and put it into the GAC will also workaround
the problem.
Also I think the Office XP PIA is also installed in the GAC, although when
we extacted the PIA dll, it is extracted to a folder, but if you look into
the GAC(%windir%\assembly), you will find it is there. In the CLR runtime,
the fusion(which do the work to find the assembly) will check GAC first to
see if the matched assembly is there.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

Creating a seperate dll for this is a mess as it needs access to classes in
my add-in. I thought of that but I don't think I can do it. And it's also bad
because it adds one more file that can be missing, wrong, etc.

As to the GAC - the official MS docs say to NOT put the XP PIAs in the GAC.
And what about the Office 2000 PIAs I created - what if someone else also
creates those and puts them in the GAC too? That is asking for trouble.

Finally, the Forms program I posted is not in the GAC and it works. So
putting it in the GAC should not be necessary.

Could you please find out what is going on here? The .NET group should be
able to figure out what the problems is - and come up with a better
work-around. And I would think they would want to know about this as it is
clearly a bug.

Also, if they do say the GAC is the only solution, and my code then requires
my entire add-in then go in the GAC, would you please ask the Word group if
there is anything special I should do for my DLL and/or the 2000/2002 PIAs
when I put them in the GAC (as all the docs say don't do this)?

I don't want to end up with something that is buggy because of where it's
installed.
 
D

David Thielen

Hello;

I've been playing around with this today and have found the following:
1) Yes putting it in the GAC lets it work (could this be a
permission/security issue)?
2) You can debug an assembly in the GAC - you have to copy the pdb file
there too to do it.
3) There is no way in my code that I can create a small helper dll. In one
of the editors I need a large chunk of the classes/data in my add-in to
present the choices to the user.

So...

Either everything goes in the GAC (my code, PIAs, etc.) or the Word/.NET
group figures out what is wrong here and comes up with a work-around.

I'd much prefer the work-around as I figure my code and the 2000/2002 PIAs
have no business being in the GAC.
 
D

David Thielen

The problems keep multiplying. If my add-in is in the GAC, then I need the
following 4 dlls that it calls in the GAC:
AxInterop.SHDocVw.dll
ICSharpCode.SharpZipLib.dll
Interop.SHDocVw.dll
Interop.sqldmo.dll

But none of these are mine and none are strongly named. So if I strong name
them and then put them in the GAC would be, in my opinion, very very bad.
Especially the 3 auto-generated interop DLLs.

But I have to have them because the editor for one of the objects in the
PropertyGrid can display data selects and what that select will find. So the
editor needs the DLLs to display IE in a control.
 
P

Peter Huang [MSFT]

Hi

Based on my further research, another workaround is to handle the
AppDomain.AssemblyResolve event:
public void OnStartupComplete(ref System.Array custom)
{
¡­
AppDomain.CurrentDomain.AssemblyResolve+=new
ResolveEventHandler(CurrentDomain_AssemblyResolve);
¡­
}

private Assembly CurrentDomain_AssemblyResolve(object sender,
ResolveEventArgs args)
{
if (args.Name == "WordPropGrid, Version=1.0.0.1, Culture=neutral,
PublicKeyToken=4d15e88a66a6490b")
//NOTE:the Addin is strongnamed in my test.
{
return this.GetType().Assembly;
}
else
{
return null;
}
}

BTW: if we look in to the register.bat shipped with Office XP PIA
installer, we will find that the assemblies will be added into GAC.
echo off

echo Microsoft Office XP Primary Interop Assemblies Registration Utility
echo Copyright (c) 2002 Microsoft(R) Corporation. All rights reserved.
echo Note: This utility must be run from the Visual Studio .NET Command
Prompt. It will not function properly otherwise.
echo Start adding primary interop assemblies to the global assembly cache.

echo on

gacutil -i Microsoft.Office.Interop.Access.dll
gacutil -i adodb.dll
gacutil -i dao.dll
gacutil -i Microsoft.Office.Interop.Excel.dll
gacutil -i Microsoft.Office.Interop.FrontPage.dll
gacutil -i Microsoft.Office.Interop.FrontPageEditor.dll
gacutil -i Microsoft.Office.Interop.Graph.dll
gacutil -i Microsoft.Office.Interop.Visio.dll
gacutil -i mscomctl.dll
gacutil -i msdatasrc.dll
gacutil -i Microsoft.Office.Interop.SmartTag.dll
gacutil -i office.dll
gacutil -i Microsoft.Office.Interop.Outlook.dll
gacutil -i Microsoft.Office.Interop.OutlookViewCtl.dll
gacutil -i Microsoft.Office.Interop.Owc.dll
gacutil -i Microsoft.Office.Interop.PowerPoint.dll
gacutil -i Microsoft.Office.Interop.Publisher.dll
gacutil -i stdole.dll
gacutil -i Microsoft.Vbe.Interop.dll
gacutil -i Microsoft.Office.Interop.Word.dll

echo off

echo End adding assemblies to the global assembly cache.

echo Start adding registry entries for each primary interop assembly.

echo on

regedit /s Microsoft.Office.Interop.Access.dll.reg
regedit /s adodb.dll.reg
regedit /s dao.dll.reg
regedit /s Microsoft.Office.Interop.Excel.dll.reg
regedit /s Microsoft.Office.Interop.FrontPage.dll.reg
regedit /s Microsoft.Office.Interop.FrontPageEditor.dll.reg
regedit /s Microsoft.Office.Interop.Graph.dll.reg
regedit /s Microsoft.Office.Interop.Visio.dll.reg
regedit /s mscomctl.dll.reg
regedit /s msdatasrc.dll.reg
regedit /s Microsoft.Office.Interop.SmartTag.dll.reg
regedit /s office.dll.reg
regedit /s Microsoft.Office.Interop.Outlook.dll.reg
regedit /s Microsoft.Office.Interop.OutlookViewCtl.dll.reg
regedit /s Microsoft.Office.Interop.Owc.dll.reg
regedit /s Microsoft.Office.Interop.PowerPoint.dll.reg
regedit /s Microsoft.Office.Interop.Publisher.dll.reg
regedit /s stdole.dll.reg
regedit /s Microsoft.Vbe.Interop.dll.reg
regedit /s Microsoft.Office.Interop.Word.dll.reg

echo off

echo End adding registry entries for each primary interop assembly.

echo Operation complete.

echo on

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

On the where to put the PIA issue - I wish MS would have a consistent
message. I went through a similiar thing with the 2003 PIAs where I wanted to
include them in my installer. The msdn articles said I could not. The
postings here by you and others said I could not.

So I contacted MS legal and they pointed out that the redist file shipped
with Office 2003 said it was fine for me to redistribute them. So I spent
hours over 2 months on this issue - and it was always fine to redistribute
them.

I just wish it was a single consistent message...
 
D

David Thielen

Thank you - this works. Once again you saved us.

--
thanks - dave

ps - Please report this wherever as a bug so it's fixed in .NET 2.0/Office
2006.
 
P

Peter Huang [MSFT]

Hi

I am glad that works for you.
BTW: Office 2003 PIA will be installed into GAC by the installer, because
we did not provide a separate install packet, so we did not suggest you
include the office 2003 PIA in your install program.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

Office 2003 PIAs are installed if Office is installed after .NET. If Office
is installed first then they are not installed.
 
P

Peter Huang [MSFT]

Hi

If so I think you may try to install the PIA after you install .NET
framework.

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Alex

"Peter Huang" said:
Hi

Based on my further research, another workaround is to handle the
AppDomain.AssemblyResolve event:

What exactly does it do?


Best wishes,
Alex.
 
P

Peter Huang [MSFT]

Hi

From MSDN
AppDomain.AssemblyResolve Event
Occurs when the resolution of an assembly fails.
Remarks
It is the responsibility of ResolveEventHandler for this event to return
the assembly that resolves the type, assembly, or resource.

To register an event handler for this event, you must have the permissions
described in the Permissions section. If you do not have the appropriate
permissions, a SecurityException occurs.

For more information about handling events, see Consuming Events.

AppDomain.AssemblyResolve Event
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemappdomainclassassemblyresolvetopic.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top