Library returns weird character

spammenao252spammenao252 Posts: 10
edited January 24, 2013 7:22AM in SmartAssembly
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
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:
Console.WriteLine("From test proj: "+ Settings.Modules.UpTarget);

Internal code:
Console.WriteLine("From obfuscated proj: " + Settings.Modules.UpTarget);

Output:
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.

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    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.
  • 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)
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    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.
  • 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:
    We have also improved support for Windows Phone 7.1 and Windows Phone 7.5, SQL CLR assemblies and assemblies using PostSharp.
    
    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.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    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.
  • I am indeed using v6.7, thanks ;)
Sign In or Register to comment.