microsoft / vs-servicehub

The service broker libraries used by Visual Studio to exchange intra- and inter-process services
MIT License
20 stars 8 forks source link

Add ISB003 analyzer to validate exported brokered services #199

Closed AArnott closed 4 months ago

AArnott commented 4 months ago

Fixes devdiv-1914458 by calling out the mistake at compile-time.

RyanToth3 commented 4 months ago

Should there also be a Warning for if someone implements the interface but forgets to add the attribute?

AArnott commented 4 months ago

Should there also be a Warning for if someone implements the interface but forgets to add the attribute?

An interesting question. It hasn't come up yet. And as you say, this feels more like a warning than the error case, which means I need a new diagnostic ID. We needed an analyzer for this because an attribute without the interface breaks VS. But an interface without the attribute doesn't break VS. I also suspect it won't be as common a user mistake because exporting a class almost always requires an export attribute.... but an export attribute that requires a specific interface to be implemented (and particularly an interface that isn't even specified in the export attribute) is far more an unusual requirement, thus leading at least one partner team to miss it. So I think for now I'll pass. Although I'm contemplating another analyzer to catch if folks use MEFv2 Import attributes on a class where this MEFv1 attribute is applied, as that's another common and very subtle bug.