What is the reason for EntitySetController being non-CLS compliant?

Topics: ASP.NET Web API
Dec 20, 2012 at 2:04 PM

I see that EntitySetController has the CLSCompliant attribute set to false, however after looking through the code it's not immediately apparent to me as to why. Any information on this would be appreciated.

Dec 20, 2012 at 6:51 PM
Edited Dec 20, 2012 at 6:53 PM

Hi Fazzamar,

Params on attributes are not CLS-compliant. In particular, this: 

public AcceptVerbsAttribute(params string[] methods);

  as used here for example: 

[AcceptVerbs("POST", "PUT")]
public virtual void CreateLink([FromODataUri] TKey key, string navigationProperty, [FromBody] Uri link)

is not CLS-compliant. Without the attribute, the assembly won’t compile. Out of curiosity, is this an issue for you? What .NET language are you using?

Dec 20, 2012 at 8:22 PM

Ahh, I see. As regards to whether it's an issue for me, not directly since I code in VB.Net, however the coding guidelines at my work dictate that our code should be CLS compliant so I'm going to have to do some explaining to my fellow developers. Worst case scenario I could change the AcceptVerbsAttribute to accept an Array of strings calling it with <AcceptVerbs({"POST","PUT"})>, and build a custom build of the dll for our use.

Dec 20, 2012 at 10:20 PM

Not really since AcceptVerbsAttribute is part of the core ASP.NET MVC and is sealed so you can't override (unless you want to recompile the whole ASPNET MVC library). What you could do instead is create your own EntitySetController (since it's more of a helper class than a required class) and dictate that only one HTTP method (POST or PUT).

Dec 20, 2012 at 10:58 PM

Good point about AcceptedVerbsAttribute being in core MVC, which I have no desire to use a recompiled version of. I suppose reimplenting will work fine, thanks for the suggestion.