How can we help you today? How can we help you today?

Linq and Anonymous Types

First of all, love SmartAssembly. It was probably the easiest obfuscation method that my team tried.

There is one thing that we find we have to constantly workaround, however. Assume you have a function that looks like this on a web form:
void whatever(someclass inputData)
{
    var mydata = from s in inputData
                         orderby s.Name
                         select new { s.Name, s.Value, Calculated = s.Field+5 };
    myDataGrid.DataSource = mydata;
    myDataGrid.DataBind();
}

If obfuscation is enabled in SmartAssembly, this web form will not work, because the anonymous type generated in mydata will have its types renamed. When you go to databind, the field names will be different and the program will fail at runtime.

I realize that as a workaround we could create actual types instead of using anonymous types, and as long as we make them protected or public it won't be obfuscated. Unfortunately, however, there are literally hundreds of these types of statements in our code and, in all reality, it defeats the purpose of anonymous types.

Is there a setting or something somewhere to exclude anonymous types from obfuscation?
gwerner
0

Comments

5 comments

  • nick.maidment
    Have you considered using custom attributes: http://www.red-gate.com/supportcenter/C ... 032253.htm ?

    I think the DoNotObfuscateAttribute and DoNotObfuscateTypeAttribute might be helpful for you?
    nick.maidment
    0
  • gwerner
    Unfortunately, I don't think custom attributes can be added to local variables within a function. (correct me if I'm wrong). And as I mentioned above, making specialized class definitions is out of the question.

    Also, that would mean finding each instance (hundreds) in a huge codebase, which would be pretty awful.

    In my opinion, and variable type that is attached to a datasource property should not be obfuscated because of the way .net data binding works.
    gwerner
    0
  • nick.maidment
    I'll cetainly suggest it to development and see what they say.
    nick.maidment
    0
  • [Deleted User]
    We've already logged this issue in our issue tracking system as SA-111. I'll let you know when we have a timeframe for fixing it.

    Mel
    [Deleted User]
    0
  • robertvh
    Any news on this issue?

    Our software stops working after obfuscating on the following line:
    PriceListInfo defaultPriceList = this.globe.Data.PriceLists.Where(pl => pl.Type == 'S' && pl.IsMain).FirstOrDefault();
    

    I guess this might be caused by this issue
    robertvh
    0

Add comment

Please sign in to leave a comment.