Red Gate forums :: View topic - Linq and Anonymous Types
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 5
SmartAssembly 5 forum

Linq and Anonymous Types

Search in SmartAssembly 5 forum
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
Jump to:  
Author Message
gwerner



Joined: 27 May 2009
Posts: 2

PostPosted: Fri Aug 06, 2010 4:30 pm    Post subject: Linq and Anonymous Types Reply with quote

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:

Code:
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?
_________________
Grady Werner
SmarterTools Inc
Back to top
View user's profile Send private message
nick.maidment



Joined: 29 Jan 2010
Posts: 74

PostPosted: Mon Aug 09, 2010 12:43 pm    Post subject: Reply with quote

Have you considered using custom attributes: http://www.red-gate.com/supportcenter/Content.aspx?p=SmartAssembly&c=SmartAssembly/help/5.0/SA_UsingCustomAttributes.htm&toc=SmartAssembly/help/5.0/toc1032253.htm ?

I think the DoNotObfuscateAttribute and DoNotObfuscateTypeAttribute might be helpful for you?
Back to top
View user's profile Send private message
gwerner



Joined: 27 May 2009
Posts: 2

PostPosted: Mon Aug 09, 2010 3:31 pm    Post subject: Reply with quote

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.
_________________
Grady Werner
SmarterTools Inc
Back to top
View user's profile Send private message
nick.maidment



Joined: 29 Jan 2010
Posts: 74

PostPosted: Thu Aug 19, 2010 1:20 pm    Post subject: Reply with quote

I'll cetainly suggest it to development and see what they say.
Back to top
View user's profile Send private message
melvyn.harbour



Joined: 15 Mar 2010
Posts: 28

PostPosted: Fri Aug 20, 2010 11:39 am    Post subject: Reply with quote

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
_________________
Melvyn Harbour
Project Manager
.NET Tools Division
Back to top
View user's profile Send private message
robertvh



Joined: 02 Dec 2010
Posts: 1

PostPosted: Thu Dec 02, 2010 7:39 pm    Post subject: Reply with quote

Any news on this issue?

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


I guess this might be caused by this issue
Back to top
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies. All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group