PostSharp cannot use anonymous types with > 127 properties

185 views Asked by At

Issue has been fixed in PostSharp 4.3.27

Given the following code in C#

 var obj = new
 {
     p0 = 0,
     p1 = 1
     p2 = 2,
     // and so on until 127 ...
     p127 = 127
 }

I get this error trying to build the project with PostSharp enabled:

Severity Code Description Project File Line Suppression State
Error error:
Unhandled exception (4.3.25.0, postsharp-net40-x86-srv.exe, CLR 4.0.30319.394802, Release): The file c:\users\johnm\documents\visual studio 2015\Projects\PostSharpTest\PostSharpTest\obj\Debug\Before-PostSharp\PostSharpTest.exe is not a valid .NET assembly. See below for details. PostSharpTest c:\users\johnm\documents\visual studio 2015\Projects\PostSharpTest\PostSharpTest\POSTSHARP
Error System.BadImageFormatException: The file c:\users\johnm\documents\visual studio 2015\Projects\PostSharpTest\PostSharpTest\obj\Debug\Before-PostSharp\PostSharpTest.exe is not a valid .NET assembly. ---> PostSharp.Sdk.AssertionFailedException: Invalid value 128 for enumeration ^Bw+U+DEY6J8e at location element type in type signature. at PostSharp.Sdk.Binary.ModuleReader.ReadTypeSignature(BufferReader& _0) at PostSharp.Sdk.Binary.ModuleReader.ReadTypeSignature(BufferReader& _0) at PostSharp.Sdk.Binary.ModuleReader.ImportTypeSpec(Int32 _0) at PostSharp.Sdk.Binary.ModuleReader.ImportTypeSpecs() at PostSharp.Sdk.Binary.ModuleReader.ReadModule() at PostSharp.Sdk.Binary.ModuleReader.ReadModule() at PostSharp.Sdk.Binary.ModuleReader.ReadModule(ReadModuleStrategy _0) at PostSharp.Sdk.CodeModel.Domain.LoadAssembly(String assemblyLocation, LoadAssemblyOptions options) at PostSharp.Sdk.Extensibility.ModuleLoadDirectFromFileStrategy.Load(Domain domain) at PostSharp.Sdk.Extensibility.Project.^LvMUl75+(ModuleLoadStrategy _0) at PostSharp.Sdk.Extensibility.Project.^63o9P8x3(ModuleDeclaration _0, ModuleLoadStrategy _1, Domain _2, ProjectInvocationParameters _3, Boolean _4) at PostSharp.Sdk.Extensibility.Project.CreateInstance(Domain domain, ProjectInvocation projectInvocation, Boolean reuseDomain) at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation) at PostSharp.Hosting.Program.ExecuteImpl() PostSharpTest c:\users\johnm\documents\visual studio 2015\Projects\PostSharpTest\PostSharpTest\POSTSHARP

The message

Invalid value 128 for enumeration ^Bw+U+DEY6J8e at location element type in type signature.

Seems to be of some significance but I'm not familiar with PostSharp internals.

Removing p127 works fine. Has anyone else encountered this limitation?

2

There are 2 answers

0
John Merchant On BEST ANSWER

This was fixed in PostSharp 4.3.27

1
Taras M. On

MulticastTargets Enumeration

Kinds of targets to which multicast custom attributes (MulticastAttribute) can apply.

So for InstanceConstructor max value is 128

Taken from here.