kamillangowski / postsharp-user-plugins

Automatically exported from code.google.com/p/postsharp-user-plugins
1 stars 0 forks source link

PostSharp fails when injecting logging if code optimization on and there is only a CR/LF after a conditional compilation directive #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Take for example the following, which is legal C# and compiles (assuming it
is in a class and PRECONDITIONS is defined:

        public static void ParameterNonZero(double parameter, string
parameterName) {
#if PRECONDITIONS
Require(!string.IsNullOrEmpty(parameterName),

MessageHelper.GetMessage(MessageHelper.ResourceKey.ExceptionParameterRequired,
"parameterName"));

            Require(parameter != 0,

MessageHelper.GetMessage(MessageHelper.ResourceKey.ExceptionParameterNonZero,
parameterName));
#endif
        }

Note there is a CR/LF (EOL) after the text "PRECONDITIONS" and before the
"Require".  There are no additional space characters in between the two
words.  

I put the following in assemblyinfo.cs:
[assembly: Log(AttributeTargetTypes = "*", EntryLevel = LogLevel.Debug,
ExitLevel = LogLevel.Debug, ExceptionLevel = LogLevel.Error)]

Build for debug works fine.  The logging works fine.  

Now I switch to release.  Build fails with:

Target PostSharp15:
    PostSharp 1.5 [1.5.6.686] - Copyright (c) Gael Fraiteur, 2005-2009.
    info PS0035: PostSharp:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm.exe
"C:\development\OnpointConnect\Current\OnpointConnect\app\OnpointConnect.Utility
\obj\Release\PostSharp\OnpointConnect.Utility.il"
/QUIET /DLL /PDB
"/RESOURCE=C:\development\OnpointConnect\Current\OnpointConnect\app\OnpointConne
ct.Utility\obj\Release\PostSharp\OnpointConnect.Utility.res"
"/OUTPUT=C:\development\OnpointConnect\Current\OnpointConnect\app\OnpointConnect
.Utility\obj\Release\OnpointConnect.Utility.dll"
/SUBSYSTEM=3 /FLAGS=1 /BASE=1700200448 /STACK=1048576 /ALIGNMENT=512
/MDV=v2.0.50727 
    unknown_location : postsharp error PS0034: PostSharp: ILASM exited with
return code 1. Tool output: 
    unknown_location : postsharp error PS0034:
C:\development\OnpointConnect\Current\OnpointConnect\app\OnpointConnect.Utility\
ParameterCheck.cs(16707566)
: error : syntax error at token ''C:\\development\\OnpointConnec' in: 
.line 43 , 43
'C:\\development\\OnpointConnect\\Current\\OnpointConnect\\app\\OnpointConnect.U
tility\\ParameterCheck.cs'
    unknown_location : postsharp error PS0034: 
    unknown_location : postsharp error PS0034: ***** FAILURE ***** 
    unknown_location : postsharp error PS0034: 
    unknown_location : postsharp error PS0034: 
    unknown_location : postsharp error PS0034: 
Done building target "PostSharp15" in project
"OnpointConnect.Utility.csproj" -- FAILED.

Now go into the project options and turn off "Optimize Code".  It builds
fine again.

After further trial and error I discovered that putting at least one space
character between "PRECONDITIONS(EOL)" and "Require" solved the problem.  I
could turn back on "Optimize Code" and the compile worked fine as did the
logging. 

Original issue reported on code.google.com by tcaban...@gmail.com on 18 Sep 2009 at 5:33