We would like our package settings to match the user's preferences for fonts
and colors. To do this we have been reading the TextEditor category settings
using the IVsFontAndColorStorage service interface. But we have run into a
problem. If we operate against a "clean" Visual Studio registry hive (using
vsregex or devenv /setup), the call to IVsFontAndColorStorage::OpenCategory
fails. And not just an E_FAIL return code failure. I get a memory exception.
I have tried passing every combination of FCSTORAGEFLAGS I can think of
(with and without FCSF_LOADDEFAULTS, with and without FCSF_READONLY, etc),
but I still get the same memory exception.
(The memory exception reads.. An unhandled exception of type
'System.AccessViolationException' occurred in System.Windows.Forms.dll
Attempted to read or write protected memory. This is often an indication
that other memory is corrupt.)
I have tried some alternate approaches. I used the
IVsFontAndColorCacheManager service interface to call CheckCache and/or
RefreshCache against the same category guid. The behavior was inconsistent.
Sometimes it would allow the subsequent calls to OpenCategory to succeed,
sometimes not.
I then tried loading the TextEditor package as a service, a querying for the
IVsFontAndColorDefaultsProvider interface. So far, so good. I was able to
call IVsFontAndColorDefaultsProvider::GetObject with success, and retrieved
the IVsFontAndColorDefaults interface for the TextEditor category. But
again, calling IVsFontAndColorDefaults::GetItemCount, ::GetItem or
::GetItemByName fails with the same memory exception.
Any idea on how to make sure the TextEditor category settings have been
initialized? (Safely?)
Thanks,
--Matthew
Matthew Etter - 23 Aug 2005 21:46 GMT
Never mind! I found that the problem actually was the fault of some custom
External Text Markers defined in another package. The package
(marker-providing package) was having its IVsTextMarkerTypeProvider
interface called before the package was initialized. The marker was
therefore providing invalid values to the TextEditor colors settings,
causing a problem in the IDE.
Sorry about the false alarm.