Library returns weird character

.NET obfuscator and automated error reporting

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

Library returns weird character

Postby spammenao252 » Mon Jan 21, 2013 10:47 pm

I excluded the class causing the issue from obfuscation (entire namespace to be exact), but whenever the code is called from outside of the library a strange character is still appended.

The class

Code: Select all
    public class Settings
    {
        public class Modules
        {
            static Modules()
            {
                List = new List<string>{UpTarget, StatDb, MainDb};
            }

            public const string UpTarget = "UpTarget";
            public const string StatDb = "StatDb";
            public const string MainDb = "MainDb";

            public static List<string> List;
        }
    }


Code from app referencing the library:

Code: Select all
Console.WriteLine("From test proj: "+ Settings.Modules.UpTarget);


Internal code:

Code: Select all
Console.WriteLine("From obfuscated proj: " + Settings.Modules.UpTarget);


Output:

Code: Select all
From test proj: UpTarget�
From obfuscated proj: UpTarget


Note the question-mark-ish character when calling from an external assembly.

The problem is that I'm trying to pass the string to look something up in a dictionary but now I'm getting a key not found error because the string is messed up.. anything I can do about this?

The library only has obfuscation enabled (lightest settings), nothing else.
spammenao252
 
Posts: 8
Joined: Sun Jan 20, 2013 11:39 pm

Postby Brian Donahue » Wed Jan 23, 2013 4:49 pm

I tried to reproduce this issue using your code example, and could not.

Maybe if you sent your project to support@red-gate.com, we could have a look.
Brian Donahue
 
Posts: 6669
Joined: Mon Aug 23, 2004 10:48 am

Postby spammenao252 » Wed Jan 23, 2013 6:31 pm

I narrowed the issue down to PostSharp. Even when PostSharp doesn't alter any code, running SA after it will cause the issue.

You can download a concise example of it here:
https://bitbucket.org/spammenao252/smartacharerror/get/master.zip

I included both a VS2010 and a VS2012 project. It occurs with both, even after setting obfuscation support to true in vs2010.

Again, it occurs even if PostSharp doesn't actually do anything... the example above illustrates this.

UPDATE:

According to dotPeek the non-obfuscated assembly also has the questionmark-icons even if PostSharp didn't handle the assembly (though it doesn't if the postsharp library is removed entirely). Regardless, the issue does not occur if I build the Caller referencing said assembly. It also doesn't happen if I obfuscate that assembly, only PostSharp (with an un-used aspect) + SmartAssembly makes it occur.

Not sure what it is that SA does that makes the Caller mess up.

UPDATE 2:

Ok, possibly even more interesting, if I first compile the Caller using the obfuscated version of the library that is not handled by PostSharp, and then swap that library out with the Obfuscated+PostSharp handled version, the program runs fine.

But when I compile the Caller using the latter library as a direct reference, and then swap it out with the former, it still crashes.

Note that the Caller doesn't have any PostSharp code and isn't handled by it at all, and that I'm also not obfuscating the Caller.

How weird is this!?

To summarize
----------------------------------------
Does not occur when:

-Compile Caller with reference to library that has PostSharp Reference
-Compile Caller with reference to library that has PostSharp Reference + Aspect
-Compile with either of those 2 and then swap the library with their obfuscated versions.

Does occur when:

-Compile Caller with reference to library that has PostSharp Reference + Obfuscation
-Compile Caller with reference to library that has PostSharp Reference + Aspect + Obfuscation
-Compile with either of those 2 and then swap the library with their non-obfuscated versions.
----------------------------------------

Also does not occur when PostSharp reference is removed entirely and the library is then obfuscated and used for compiling the Caller (as expected ofc)
spammenao252
 
Posts: 8
Joined: Sun Jan 20, 2013 11:39 pm

Postby Brian Donahue » Thu Jan 24, 2013 10:14 am

I don't think SA works with PostSharp...
http://www.sharpcrafters.com/blog/post/ ... or%29.aspx

But we have some information that it *may* work if you use PostSharp before you use SmartAssembly. I guess you can give that a try.
Brian Donahue
 
Posts: 6669
Joined: Mon Aug 23, 2004 10:48 am

Re:

Postby spammenao252 » Thu Jan 24, 2013 10:55 am

Brian Donahue wrote:I don't think SA works with PostSharp...
http://www.sharpcrafters.com/blog/post/ ... or%29.aspx

That's incorrect. http://www.sharpcrafters.com/blog/post/SmartAssembly-now-supports-PostSharp.aspx

And also: http://www.red-gate.com/SupportCenter/content/SmartAssembly/articles/version_6xx_SmartAssembly which states:

Code: Select all
We have also improved support for Windows Phone 7.1 and Windows Phone 7.5, SQL CLR assemblies and assemblies using PostSharp.

Brian Donahue wrote:But we have some information that it *may* work if you use PostSharp before you use SmartAssembly. I guess you can give that a try.

But that's what I'm already doing. I'm compiling the library with Postsharp enabled, I then obfuscate that library and reference it from the main assembly (Caller) which doesn't use PostSharp at all.

Weirdest of all is that it works fine if I compile the Caller using the non-obfuscated library, and then swap that dll file out with the obfuscated version. This means it's an issue with compiling using an obfuscated library rather than an issue with the library itself.

There seems to be something about the SA + PostSharp combo that makes the Caller mess up constants in the library at compile time.
spammenao252
 
Posts: 8
Joined: Sun Jan 20, 2013 11:39 pm

Postby Brian Donahue » Thu Jan 24, 2013 11:10 am

Thanks for the update. Unfortunately I don't have the opportunity to keep up with the .NET world, so I'll put that link in our internal KB.

I don't know if this is a PostSharp problem or a SmartAssembly problem.

Please ensure you are using at least SmartAssembly 6.7 and let me know that.

If you are, I will raise it as a development issue.
Brian Donahue
 
Posts: 6669
Joined: Mon Aug 23, 2004 10:48 am

Postby spammenao252 » Thu Jan 24, 2013 1:22 pm

I am indeed using v6.7, thanks ;)
spammenao252
 
Posts: 8
Joined: Sun Jan 20, 2013 11:39 pm


Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 0 guests