Sometimes SA doesn't give error return codes

.NET obfuscator and automated error reporting

Moderators: Luke Jefferson, melvyn.harbour, dom.smith

Sometimes SA doesn't give error return codes

Postby nyxling » Wed Jul 09, 2014 4:18 pm

I'm using SA v6.8.0.121 and have set it up to run in my TeamCity-based build server-- I've got it all working as desired, except that in some (all?) cases, when SA fails to obfuscate, it doesn't actually give an error (read: non-zero) return code, so TeamCity never knows to flag that step of the build process as having failed.

As it is right now, I need to manually check every build log's obfuscation step to see if SA output any error text, because it'll just happily have an error, and then tell TeamCity that were wasn't one.

An example of where I've seen this happen:
Code: Select all
[00:07:14]Step 5/5: Obfuscate (Command Line) (30s)
[00:07:14]Starting: C:\\TeamCity\\buildAgent\\temp\\agentTmp\\custom_script6461944242385122991.cmd
[00:07:14]in directory: C:\\TeamCity\\buildAgent\\work
[00:07:16]SmartAssembly v6.8.0.121
[00:07:16]Copyright ¸ Red Gate Software 2005-2013
[00:07:19]Loading project C:\\TeamCity\\buildAgent\\work\\0001/../Obfuscate.saproj
[00:07:19]Loading...
[00:07:31]Starting...
[00:07:31]Analyzing...
[00:07:41]Preparing...
[00:07:44]Failed
[00:07:44]SmartAssembly.InformationException: SmartAssembly has encountered an invalid symbol:
[00:07:44]
[00:07:44][mscorlib]System.Collections.ArrayList
[00:07:44]
[00:07:44]The most likely cause is that SmartAssembly has used a different version of a dependency from the version used by Assembly-CSharp.dll.
[00:07:44]
[00:07:44]If the details below are wrong, please use the MandatoryPath attribute in the .saproj file to ensure that the correct version of the dependency is found.
[00:07:44]
[00:07:44]Assembly that should contain the missing symbol: C:\\TeamCity\\buildAgent\\work\\0001\\0001_Data\\Managed\\mscorlib.dll
[00:07:44]
[00:07:44]
[00:07:44]SmartAssembly has encountered an error while running your project.
[00:07:44]Failed: SmartAssembly.InformationException: SmartAssembly has encountered an invalid symbol:
[00:07:44]
[00:07:44][mscorlib]System.Collections.ArrayList
[00:07:44]
[00:07:44]The most likely cause is that SmartAssembly has used a different version of a dependency from the version used by Assembly-CSharp.dll.
[00:07:44]
[00:07:44]If the details below are wrong, please use the MandatoryPath attribute in the .saproj file to ensure that the correct version of the dependency is found.
[00:07:44]
[00:07:44]Assembly that should contain the missing symbol: C:\\TeamCity\\buildAgent\\work\\0001_Build\\0001_Data\\Managed\\mscorlib.dll
[00:07:44]Please run SmartAssembly in User-Interface mode for more information.
[00:07:45]Process exited with code 0


I've since fixed that error, but the fact that we were assuming all was well when it in fact WASN'T is a little concerning. The last thing we want is for obfuscation to fail, and we release thinking it succeeded.
nyxling
 
Posts: 7
Joined: Mon Mar 31, 2014 3:41 pm

Postby jessica.ramos » Thu Jul 10, 2014 10:19 pm

Hi Jed,

Thanks for your post!

I apologize in advance if these questions are a bit stupid! However, I don't have much experience with Team City..

Can I please check:
- Is the .cmd file calling on SmartAssembly.com?
- And is that "Process exited with code 0" referring to the smartassembly.com process or to the overall Team City build?

I did a quick check and when a build fails with that invalid symbol error, it should make smartassembly.com exit with error code 1.

I wonder if there might be some TeamCity setting that could be making the step go through as successful?

(I also found one blog post that mentioned that when running msbuild from powershell, powershell will return 0 even if msbuild fails--I'm not sure if this could be related somehow - http://alsagile.com/post/27403222324/us ... ntegration)
Jessica Ramos
Technical Support
Red Gate Software Ltd.
jessica.ramos
 
Posts: 235
Joined: Mon Apr 23, 2012 1:13 pm

Postby nyxling » Fri Jul 11, 2014 10:26 pm

Hi Jessica,

This is the contents of the .cmd file (it's just a .bat file)
Code: Select all
IF NOT EXIST "0001_Obfuscate" ( mkdir "0001_Obfuscate" )
IF EXIST "0001_Obfuscate\\Assembly-CSharp.dll" ( del "0001_Obfuscate\\Assembly-CSharp.dll" )
"C:\\Program Files\\Red Gate\\SmartAssembly 6\\SmartAssembly.com" /build "%system.teamcity.build.checkoutDir%/../0001.saproj"
IF EXIST "0001_Obfuscate\\Assembly-CSharp.dll" ( copy "0001_Obfuscate\\Assembly-CSharp.dll" "0001_Build\\0001_Data\\Managed\\Assembly-CSharp.dll" )


As you can see, there are a few directory/file management lines, but basically it's just calling SmartAssembly, and to answer your questions:
1) Yes, it's calling SmartAssembly.com
2) I'm not 100% sure. I no longer have the failed build on my machine, so I can't check it's log directly, and as such, I don't know definitively whether the "Process exited with code 0" line was collapsed with the rest of the "Step5/5" stuff or not. (it auto-collapses each step's logs to make them separately viewable) HOWEVER, the overall build process was considered a success by TeamCity, and it's designed to detect errors so it can report them as a failed build. That said, if SmartAssembly had returned non-zero, it -should- have caused the entire build to fail.

I suppose there's a chance that there's a bug in TeamCity, but the fact that during configuration, I've gotten tons of errors leading to failed builds has lead me to believe that it's SmartAssembly and not TeamCity. But I'm not discounting the possibility^^

I'll have to take a look at that blog post and see if it applies to my situation, when I have time. I'll be sure to get back to you about that.
nyxling
 
Posts: 7
Joined: Mon Mar 31, 2014 3:41 pm

Re:

Postby DanielRose » Mon Jul 14, 2014 3:02 pm

nyxling wrote:
Code: Select all
IF NOT EXIST "0001_Obfuscate" ( mkdir "0001_Obfuscate" )
IF EXIST "0001_Obfuscate\\Assembly-CSharp.dll" ( del "0001_Obfuscate\\Assembly-CSharp.dll" )
"C:\\Program Files\\Red Gate\\SmartAssembly 6\\SmartAssembly.com" /build "%system.teamcity.build.checkoutDir%/../0001.saproj"
IF EXIST "0001_Obfuscate\\Assembly-CSharp.dll" ( copy "0001_Obfuscate\\Assembly-CSharp.dll" "0001_Build\\0001_Data\\Managed\\Assembly-CSharp.dll" )



AFAIK the copy command sets the errorlevel as well. So if the SA build fails, but the file was created, it gets copied. If copying succeeded, this will return 0.

So the correction would be:
Code: Select all
"C:\\Program Files\\Red Gate\\SmartAssembly 6\\SmartAssembly.com" /build "%system.teamcity.build.checkoutDir%/../0001.saproj"
IF ERRORLEVEL 1 EXIT 1
IF EXIST "0001_Obfuscate\\Assembly-CSharp.dll" ( copy "0001_Obfuscate\\Assembly-CSharp.dll" "0001_Build\\0001_Data\\Managed\\Assembly-CSharp.dll" )
DanielRose
 
Posts: 16
Joined: Fri Oct 30, 2009 9:29 am
Location: Aachen, Germany

Postby nyxling » Mon Jul 14, 2014 3:26 pm

Hey there, I just logged in to check/post my solution, and it turns out that I had found the same thing as DanielRose.

For a while there I was originally thinking that the "Process exited with code 0" actually referred to the commandline process, which would always simply returns 0 when it finished, but testing with a failed copy as the last line proved that suspicion wrong, as it would then return code 1.
nyxling
 
Posts: 7
Joined: Mon Mar 31, 2014 3:41 pm

Postby nyxling » Mon Jul 21, 2014 3:43 pm

It appears that the link that Jessica provided is indeed what I needed to make things work properly, so I would consider this issue closed.
nyxling
 
Posts: 7
Joined: Mon Mar 31, 2014 3:41 pm


Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 0 guests