0

I developed code in a single non-compiled .aspx page that ran great, but when I copy-pasted the code into a code-behind page the c# compiler is raising an error:

error CS1061: 'System.Collections.Generic.IEnumerable' does not contain a definition for 'Descendants' and no extension method 'Descendants' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

The line in question:

 xdoc = System.Xml.Linq.XDocument.Parse(xmlReminders);
 var xdocReminders = from reminder in xdoc.Descendants("Reminders").Descendants("Reminder") select reminder;

The compiler command references System.Xml.Linq.dll

csc.exe [...bunch of stuff...]  /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Xml.Linq.dll

and MSDN has this method in XElement's documentation:

Descendants(XName): Returns a filtered collection of the descendant elements for this document or element, in document order. Only elements that have a matching XName are included in the collection. (Inherited from XContainer.)

Why would the same code compile and run at run-time on the server, but not compile manually?

For reference, the compile command is:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Csc.exe /nowarn:162,618,1701,1702 /reference:bin\aspNetEmail.dll /reference:bin\aspNetMime.dll /reference:bin\aspNetPOP3.dll /reference:bin\Google.GData.AccessControl.dll /reference:bin\Google.GData.Calendar.dll /reference:bin\Google.GData.Client.dll /reference:bin\Google.GData.Extensions.dll /reference:bin\DateTimePicker.dll /reference:bin\itextsharp.dll /reference:bin\AE.Net.Mail.dll /reference:bin\Newtonsoft.Json.dll /reference:bin\PushSharp.Apple.dll /reference:bin\PushSharp.Core.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Configuration.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Drawing.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.EnterpriseServices.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Web.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Web.Mobile.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Web.Services.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Xml.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.Xml.Linq.dll /debug+ /debug:full /optimize+ /out:bin\MyDLL.dll /target:library [list of files]

crthompson
  • 15,653
  • 6
  • 58
  • 80
MarkF
  • 952
  • 2
  • 8
  • 25
  • 2
    imported `using System.Xml.Linq` namespace ?? – Dgan Sep 13 '14 at 05:34
  • That was it. I thought I would not need to do that if I provided the full System.Xml.Linq.XDocument namespace in the variable declaration. – MarkF Sep 13 '14 at 07:26

0 Answers0