Click here to Skip to main content
11,927,190 members (50,228 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# testing

I am not able to access private variable value using PrivateObject if my library is obfuscated. i know the variable name and other information are changed when we do obfuscation but is there any workaround for that ?

if i am accessing private variable of the serialized class then it is working fine but non-serialized class's private variables are not accessible using PrivateObject.

can anyone suggest any other solution to get private variable value ?

Posted 31-May-12 0:32am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Does your obfuscator generate a log file which tells you what each method/field was translated to? If so, you might be able to use that to reverse the mappings in your test harness and look up the post-obfuscation value.

Note that if you're using reflection looking for known class/method/property names in your actual code (as opposed to the tests), you will need to exclude the targets of that reflection from obfuscation.
amitgajjar 31-May-12 6:51am
i only have obfuscated library,even i don't know which tool is used to obfuscate :)
BobJanova 31-May-12 9:36am
Then you're pretty much screwed, the whole purpose of obfuscation is to remove meaning from the compiled code (IL in this case) so if you're looking for particular meaningful names you will not succeed.
amitgajjar 1-Jun-12 0:31am
actually i have created lots of test cases for checking private variable. but till date we are checking on non-obfuscated library. now client have requirement to check our all test cases on obfuscated library. so stuck there... :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 31 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100