I've created and proffered a service successfully (at least I think so, no
errors were generated when it was added) but im unable to retrieve the
service later on.
I have an assembly which defines the interface the service uses.
In another assembly, I define the class and give it a Guid attribute. In the
same assembly, I have a custom package which creates an instance of the
object and proffers the service in its Initialize function. It also carries
the ProvideService attribute.
I'm trying to use the service in a 3rd assembly. I have a custom UI editor
implemented in this assembly. The Edit function of the UITypeEditor receives
an IServiceProvider, but calling GetService with my service information
returns null. The only thing I can think of is that the IServiceProvider
given in the UITypeEditor is different then the one I added my service to.
But I have no idea how to verify this or how to get around it.
Thanks!
Bill
Heres a quick code dump...
1st Assembly (the interface assembly)
public interface IArcherEditorProviderService
{
ICodeField ViewCode(ICodeField fld);
}
2nd Assembly (the package)
[Guid("22E837BC-7CBA-4352-8963-9999022EDCFE")]
public class ArcherEditorProviderService : IArcherEditorProviderService
{
public ArcherEditorProviderService(InstrumentPackage pkg)
{
m_Pkg = pkg;
}
private InstrumentPackage m_Pkg;
public ICodeField ViewCode(ICodeField fld)
{
return m_Pkg.ViewCode(fld);
}
}
[MSVSIP.Helper.ProvideService("22E837BC-7CBA-4352-8963-9999022EDCFE",
ServiceName="ArcherEditorProviderService")]
public class InstrumentPackage :
MSVSIP.Helper.Package,MSSHELL.IVsRunningDocTableEvents3,MSSHELL.IVsSolutionE
vents3,MSSHELL.IVsTaskProvider2
{
protected override void Initialize()
{
// even though the docs dont specify this, the PackageHelper does implement
IServiceContainer so this cast is safe.
((IServiceContainer)this).AddService(typeof(IArcherEditorProviderService),
new ArcherEditorProviderService(this), true);
}
}
3rd Assembly (the consumer)
public class CodeFieldEditor : System.Drawing.Design.UITypeEditor
{
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
IArcherEditorProviderService svc =
(IArcherEditorProviderService)provider.GetService(typeof(IArcherEditorProvid
erService));
if (svc != null)
{
return svc.ViewCode(f);
}
}
}
"Ed Dore [MSFT]" - 10 Aug 2004 23:46 GMT
Hi Bill,
I believe you are correct that the IServiceProvider passed to the
UITypeEditor is not the same as the one your package gets via it's SetSite.
You may want to try Querying for IServiceProvider off of the DTE automation
object instead, and then use it to call QueryService to retrieve your
service. Just a guess.
Sincerely,
Ed Dore [MSFT]
This post is 'AS IS' with no warranties and confers no rights.
Bill Foust - 11 Aug 2004 17:19 GMT
I'm sorry Ed, I'm not getting something here. The DTE doesnt have an
IServiceProvider that I can find.
Bill
> Hi Bill,
>
[quoted text clipped - 8 lines]
>
> This post is 'AS IS' with no warranties and confers no rights.