Method in enum Error - Cant Compile
8 posts • Page 1 of 1
Method in enum Error - Cant Compile
I get an error when compiling my project. I've been through all the samples and created a couple of test projects. Created my aspect attributes off of you XTrace samples. All of this worked and worked well for my small sample apps. I was sold that it would work and work well.
Then i wired everything up in my solution, very big solution mind you. 29 projects in the solution. I only added the attribute to one project to test it out and add to the others gradually. The project i added to is a pretty large project though.
This is what was added to the AssemblyInfo.cs file.
When compiling all other projects compile fine but the one that has the attributes included failed with these lines in the build output.
There are exactly 45 errors like this.
V:\MASK_APP_SOLUTION_PATH\obj\Debug\PostSharp\MASK_APP_PROJECT_NAME.il (461807): postsharp error PS0033: PostSharp: [ILASM] Method in enum
Then this is the final error.
unknown_location : postsharp error PS0080: PostSharp: The process "ILASM" did not terminate in due time and was killed.
Done building project "MASK_APP_PROJECT_NAME.csproj" -- FAILED.
What could be wrong? Does this have something to do with enums? I searched the forums and didnt find anyone else asking this.
Please help.
-Reg
Then i wired everything up in my solution, very big solution mind you. 29 projects in the solution. I only added the attribute to one project to test it out and add to the others gradually. The project i added to is a pretty large project though.
This is what was added to the AssemblyInfo.cs file.
- Code: Select all
[assembly: PXSTraceMethodInvocationAttribute]
[assembly: PXSTraceFieldAccessAttribute]
When compiling all other projects compile fine but the one that has the attributes included failed with these lines in the build output.
There are exactly 45 errors like this.
V:\MASK_APP_SOLUTION_PATH\obj\Debug\PostSharp\MASK_APP_PROJECT_NAME.il (461807): postsharp error PS0033: PostSharp: [ILASM] Method in enum
Then this is the final error.
unknown_location : postsharp error PS0080: PostSharp: The process "ILASM" did not terminate in due time and was killed.
Done building project "MASK_APP_PROJECT_NAME.csproj" -- FAILED.
What could be wrong? Does this have something to do with enums? I searched the forums and didnt find anyone else asking this.
Please help.
-Reg
- rhenderson
- Posts: 9
- Joined: Sat Apr 12, 2008 9:18 pm
- Full Name: Reginald Henderson
- Company: Platinum Xun Solutions
Re: Method in enum Error - Cant Compile
I just looked in the IL that is generated by PostSharp and noticed that on the line that failed there is an enum struct there or close to it.
So in my small test app i put an enum right above main in my class. like so...
Putting this enum CarColors causes PostSharp to fail compiling. Is there a way to filter out enum or is there a proper way to handle enums?
So in my small test app i put an enum right above main in my class. like so...
- Code: Select all
namespace BlackMarket
{
internal static class Program
{
enum CarColors
{
Blue = 5,
Green = 8,
Yellow = 9,
Brown = 76
}
private static void Main()
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Putting this enum CarColors causes PostSharp to fail compiling. Is there a way to filter out enum or is there a proper way to handle enums?
- rhenderson
- Posts: 9
- Joined: Sat Apr 12, 2008 9:18 pm
- Full Name: Reginald Henderson
- Company: Platinum Xun Solutions
Re: Method in enum Error - Cant Compile
You found a bug!
The OnFieldAccessAspect should not apply on "literal" fields (enum, const), but there is no guard.
A workaround is to explicitely exclude your enums:
Of course the workaround will not be very helpful in a big solution.
Could you please file a bug report? I will repair it asap.
Thanks,
Gael
The OnFieldAccessAspect should not apply on "literal" fields (enum, const), but there is no guard.
A workaround is to explicitely exclude your enums:
[PXSTraceFieldAccessAttribute(AttributeExclude=true)]
public enum MyEnum
{
}
Of course the workaround will not be very helpful in a big solution.
Could you please file a bug report? I will repair it asap.
Thanks,
Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 608
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Method in enum Error - Cant Compile
Just noticed something else. In my test app if i remove the line
It compiles and works. Is there something i can do in the FieldAccessAttribute to make this work. My code is the same as your XTrace sample code with some tweaks in the method bodies (structure is the same though).
Seems like it's trying to treat enums as Properties/Fields. Anyway to filter enums out of this?
- Code: Select all
[assembly: PXSTraceFieldAccessAttribute]
It compiles and works. Is there something i can do in the FieldAccessAttribute to make this work. My code is the same as your XTrace sample code with some tweaks in the method bodies (structure is the same though).
Seems like it's trying to treat enums as Properties/Fields. Anyway to filter enums out of this?
- rhenderson
- Posts: 9
- Joined: Sat Apr 12, 2008 9:18 pm
- Full Name: Reginald Henderson
- Company: Platinum Xun Solutions
Re: Method in enum Error - Cant Compile
Oh yes, another workaround is to use CompileTimeValidate. Return false is the field is constant:
- Code: Select all
public override bool CompileTimeValidate(FieldInfo field )
{
return (field.Attributes & FieldAttributes.Literal) == 0;
}
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 608
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: Method in enum Error - Cant Compile
I feel pretty good to know I've found a bug in a well designed product. Kind of surprised but anyway.
I'll wait on the bug fix to use the field aspect. My solution is really huge and going through and adorning all enums is not something i want to do at this point.
The other "CompileTimeValidate" work around makes things better but it still errors. Before this work around i would get 11 "method in enum" errors from that small CarColors enum. After this work around i get 3. Much better but if it doesnt compile i'm still out of luck.
I'll log the error as a bug.
-Reg
I'll wait on the bug fix to use the field aspect. My solution is really huge and going through and adorning all enums is not something i want to do at this point.
The other "CompileTimeValidate" work around makes things better but it still errors. Before this work around i would get 11 "method in enum" errors from that small CarColors enum. After this work around i get 3. Much better but if it doesnt compile i'm still out of luck.
I'll log the error as a bug.
-Reg
- rhenderson
- Posts: 9
- Joined: Sat Apr 12, 2008 9:18 pm
- Full Name: Reginald Henderson
- Company: Platinum Xun Solutions
- rhenderson
- Posts: 9
- Joined: Sat Apr 12, 2008 9:18 pm
- Full Name: Reginald Henderson
- Company: Platinum Xun Solutions
Re: Method in enum Error - Cant Compile
I didnt have a way to update the bug report with feedback on the latest fix but for bug http://www.postsharp.org/tracker/view.php?id=196 the latest release version 1.0.8.326 works!
I didnt try the updated workaround but the new version fixes the issue. Award winning support
. One day i'm reporting an issue in the forum, the next day i get a new version with the fix. Awesome!
Thanks dude.
-Reg
I didnt try the updated workaround but the new version fixes the issue. Award winning support
Thanks dude.
-Reg
- rhenderson
- Posts: 9
- Joined: Sat Apr 12, 2008 9:18 pm
- Full Name: Reginald Henderson
- Company: Platinum Xun Solutions
8 posts • Page 1 of 1