Forums

Help with XDocument in System.Xml.Linq

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Help with XDocument in System.Xml.Linq

Postby taylorzr » Wed Feb 09, 2011 9:22 pm

Hello everybody,

I have python experience but I'm new to both cobra and c#. I've trying to write a small application that loads and parses an xml document.

I've written it in python and I've got it working in c# but get an error in cobra:

C#:
Code: Select all
using System.Xml.Linq;

class Program
{
    public static void Main()
    {
        XDocument ticket = XDocument.Load("ticket.xml");
        ...


Cobra:
Code: Select all
use System.Xml.Linq

class Program
    def main
        xml = XDocument.load('ticket.xml')
        ...


Error:
Code: Select all
(empty)(1): error: Cannot implement "Object" which is a class. Use "inherits" in
stead.
Compilation failed - 1 error, 0 warnings
Not running due to errors above.


What am I missing?

-Zach
taylorzr
 
Posts: 6

Re: Help with XDocument in System.Xml.Linq

Postby Charles » Thu Feb 10, 2011 1:09 am

I can reproduce the problem, but for added information can you tell me your op sys name and version, vm version and Cobra version? I always like to know what people are using, especially when they find a bug.

Sorry this was your first (or early) experience with Cobra. Thanks for reporting it.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Help with XDocument in System.Xml.Linq

Postby Charles » Thu Feb 10, 2011 1:26 am

Your fix is to explicitly reference the System.Xml library with @ref:
@ref 'System.Xml'

use System.Xml.Linq

class Program
def main
xml = XDocument.load('ticket.xml')
print 'done.'

Or via the command line:
Code: Select all
cobra -c -ref:System.Xml xml.cobra

Obviously, it's a bad user experience to get such a cryptic error message. I'll look into fixing that.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Help with XDocument in System.Xml.Linq

Postby taylorzr » Thu Feb 10, 2011 7:26 pm

OS Version: Windows 7
VM Version: .Net 4.0*
Cobra Version: 0.8

*I'm a little unsure on this. I know I have .Net 4.0 installed. But maybe Cobra is referencing an older version. The MSDN documentation shows XDocument as available in .Net 4.0 & 3.5 only.

When I added the ref to System.Xml I get the error:
Code: Select all
 error: Metadata file "System.Xml.Linq.dll" could not be found


Thanks for the quick response. I'm really excited about this language. I'm an amateur programmer. I've taught myself python for the last ~2 years and I like it. But my company's software deployment consists of Java and .Net and I have no way of deploying python. I like the idea of a 4kb compiled cobra application not a 5mb packaged python application.

So csharp works, but I dislike the syntax and verbosity. Cobra is so much more elegant and flexible. And with built in testing. I might actually write tests :)
taylorzr
 
Posts: 6

Re: Help with XDocument in System.Xml.Linq

Postby Charles » Fri Feb 11, 2011 9:59 pm

I'm glad you like Cobra.

I experience the same problem on Windows 7 64-bit, even using the latest Cobra from source. I'm looking into it.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Help with XDocument in System.Xml.Linq

Postby Charles » Fri Feb 11, 2011 10:23 pm

Based on the presumption that this was a problem of .NET 2.0 vs. 3.5, I tried this approach and it worked:

Code: Select all
cobra -native-compiler:C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe xml.cobra


There is also a 64-bit version you can try if the above fails you:
Code: Select all
cobra -native-compiler:C:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe xml.cobra


If your "cobra" command in your PATH is a .bat or .cmd file, you can enhance it to pass the -native-compiler option down to cobra.exe so you don't have to do this every time.

My current code is then:
@ref 'System.Xml'

use System.Xml
use System.Xml.Linq

class Program

def main
xml = XDocument.load('ticket.xml')
trace xml
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Help with XDocument in System.Xml.Linq

Postby taylorzr » Sat Feb 12, 2011 9:55 am

Awesome. Thanks for your help. Compiles and runs as expected now.

I modified the .bat from:
Code: Select all
@"C:\Cobra\Cobra-0.8.0-post\bin\cobra.exe" %*


to:
Code: Select all
@"C:\Cobra\Cobra-0.8.0-post\bin\cobra.exe" -native-compiler:C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe %*
taylorzr
 
Posts: 6


Return to Discussion

Who is online

Users browsing this forum: No registered users and 63 guests