Click here to Skip to main content
15,886,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to compile the following snippet with CodeDom:
C#
var res = from x in q.Rows
group x by x.Product into g
select new 
{
    Product = g.Key,
    TotalPrice = g.Sum(p => p.Price),
    TotalQTY = g.Sum(p => p.QTY)
};

return q.ToList<object>();
With the following references :
C#
compilerparams.ReferencedAssemblies.Add(typeof(object).Assembly.Location); //mscorlib.dll
compilerparams.ReferencedAssemblies.Add(typeof(System.Uri).Assembly.Location); //system.dll
                compilerparams.ReferencedAssemblies.Add(typeof(System.Linq.Enumerable).Assembly.Location);//system.core.dll

But the compiler complains that it can't find GroupBy and ToList extension methods.
Posted
Comments
Sergey Alexandrovich Kryukov 28-Oct-13 15:28pm    
Your method of finding assemblies to reference is good, but extension methods syntax is different — where is your "using" clause? This is what can be a problem...
—SA
Mehdi Gholam 28-Oct-13 23:56pm    
Embarrassingly you are right I missed the using Sysetm.Ling.
Sergey Alexandrovich Kryukov 29-Oct-13 0:28am    
I'm glad my educated guess hit the target; to close the issue, I added a formal "solution". I hope you can accept it now... :-)
—SA

1 solution

Add appropriate "using" clause; unlike other syntactic features of the language, when you can use full type names or alias using, extension methods require "using" clause with the namespace where the extension method is declared.

—SA
 
Share this answer
 
Comments
Mehdi Gholam 29-Oct-13 1:02am    
5'ed thanks
Sergey Alexandrovich Kryukov 29-Oct-13 9:58am    
My pleasure. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900