| Author |
Message |
spammenao252
Joined: 20 Jan 2013 Posts: 8
|
Posted: Mon Jan 21, 2013 10:47 pm Post subject: Library returns weird character |
|
|
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: |
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: |
| Console.WriteLine("From test proj: "+ Settings.Modules.UpTarget); |
Internal code:
| Code: |
| Console.WriteLine("From obfuscated proj: " + Settings.Modules.UpTarget); |
Output:
| Code: |
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. |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6343 Location: Red Gate Software
|
Posted: Wed Jan 23, 2013 4:49 pm Post subject: |
|
|
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
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
spammenao252
Joined: 20 Jan 2013 Posts: 8
|
Posted: Wed Jan 23, 2013 6:31 pm Post subject: |
|
|
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) |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6343 Location: Red Gate Software
|
|
| Back to top |
|
 |
spammenao252
Joined: 20 Jan 2013 Posts: 8
|
Posted: Thu Jan 24, 2013 10:55 am Post subject: Re: |
|
|
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: |
| 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. |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6343 Location: Red Gate Software
|
Posted: Thu Jan 24, 2013 11:10 am Post subject: |
|
|
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
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
spammenao252
Joined: 20 Jan 2013 Posts: 8
|
Posted: Thu Jan 24, 2013 1:22 pm Post subject: |
|
|
I am indeed using v6.7, thanks  |
|
| Back to top |
|
 |
|