I’m creating an asmx webservice in an existing .Net 3.5 website. I would like to return a post based on a key. I would like to return the post as an anonymous type, but it is giving me the following error:
Feature ‘anonymous types’ cannot be used because it is not part of the
ISO-2 C# language specification.
Here is a screen-dump of the problem:

Any ideas how to solve this?
Note: my asmx is standing on its own. It contains the code, it has no .cs behind it.
The first problem is that you are returning an
object.As WebService produce definitions (WSDL), how do you expect the definition to be generated without knowing the actual type ?
You should introduce a DTO styled – class (no logic, only data) like :
And change your definition to return such class.
The amount of code is quite light.
[Edit] The above solution will solve your problem. However, the exact source of the problem is this one :
When you works in a .cs file, the compiler used is the compiler of the target framework of your project (3.5 here). The compilation occurs at coding time.
When you works in a .asmx file, the compilation will occurs when the asp.net application will be loaded. The compiler used in the compiler of the asp.net runtime, which is, for the .Net 3.5, the compiler for 2.0 runtime. It’s because the Framework 3.5 is only a new set of classes, but the CLR is still in V2 (changed with the V4). In this case, even if your project is in 3.5, only the code in .cs files can use 3.5 language features. All code in aspx and asmx files can only use V2 language feature.