'OptionalField' could not be found

N

Nikola Skoric

Hello,

This is the first time I try to use [OptionalField] thingy. I think I
use it in a proper way. But, I have following code:


using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;

namespace LanguageSystem {
[...]
[Serializable]
public class LangLanguage {
public enum Orient {LeftToRight, RightToLeft};

public string Name;
public ArrayList alphabet;
public Orient orientation;
[OptionalField]
public int wordNumber;

And it produces following error:

C:\[...]\LangLanguage.cs(19): The type or namespace name
'OptionalField' could not be found (are you missing a using directive or
an assembly reference?)

What could possibly be the problem?
 
D

Dave Sexton

Hi,

OptionalFieldAttribute is under the System.Runtime.Serialization namespace.
It's defined in the mscorlib assembly just like SerializableAttribute, which
you are using as well. The code you have posted looks fine to me, but the
error is definitely indicating that you're missing the using directive or a
reference to mscorlib, which is doubtful. If you remove [OptionalField]
from your code does it compile?

If you're using VS 2005 you should notice that the color of OptionalField
changes to teal (if you haven't defined a different color) to indicate that
it's a type. If the color doesn't change then you haven't add the using
System.Runtime.Serialization directive as in your example or you actually
are missing a reference to mscorlib.
 
N

Nikola Skoric

dave@jwa said:
Hi,

OptionalFieldAttribute is under the System.Runtime.Serialization namespace.
It's defined in the mscorlib assembly just like SerializableAttribute, which
you are using as well. The code you have posted looks fine to me, but the
error is definitely indicating that you're missing the using directive or a
reference to mscorlib, which is doubtful. If you remove [OptionalField]
from your code does it compile?

Yes, it does.
If you're using VS 2005 you should notice that the color of OptionalField
changes to teal (if you haven't defined a different color) to indicate that
it's a type. If the color doesn't change then you haven't add the using
System.Runtime.Serialization directive as in your example or you actually
are missing a reference to mscorlib.

I have VS 2002m, therefore no teal :) But, as you see, I did use
System.Runtime.Serialization and I can compile the code with
[Serializable], but can't with [OptionalField]. [OptionalField] is the
problem here. Could it be something with [OptionalField] being added to
standard later, so my version of framework and/or compiler doesn't
recognise it?
 
D

Dave Sexton

Hi Nikola,
Could it be something with [OptionalField] being added to
standard later, so my version of framework and/or compiler doesn't
recognise it?

Yes! (Sorry I didn't think of that :)

OptionalFieldAttribute was added to the 2.0 framework.

--
Dave Sexton
http://davesexton.com/blog

Nikola Skoric said:
dave@jwa said:
Hi,

OptionalFieldAttribute is under the System.Runtime.Serialization
namespace.
It's defined in the mscorlib assembly just like SerializableAttribute,
which
you are using as well. The code you have posted looks fine to me, but
the
error is definitely indicating that you're missing the using directive or
a
reference to mscorlib, which is doubtful. If you remove [OptionalField]
from your code does it compile?

Yes, it does.
If you're using VS 2005 you should notice that the color of OptionalField
changes to teal (if you haven't defined a different color) to indicate
that
it's a type. If the color doesn't change then you haven't add the using
System.Runtime.Serialization directive as in your example or you actually
are missing a reference to mscorlib.

I have VS 2002m, therefore no teal :) But, as you see, I did use
System.Runtime.Serialization and I can compile the code with
[Serializable], but can't with [OptionalField]. [OptionalField] is the
problem here. Could it be something with [OptionalField] being added to
standard later, so my version of framework and/or compiler doesn't
recognise it?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
 
N

Nikola Skoric

dave@jwa said:
Hi Nikola,
Could it be something with [OptionalField] being added to
standard later, so my version of framework and/or compiler doesn't
recognise it?

Yes! (Sorry I didn't think of that :)

OptionalFieldAttribute was added to the 2.0 framework.

Can I then just install 2.0 framework and everything's fine or do I have
to upgrade the VS too?
 
D

Dave Sexton

Hi Nikola,

Well you could download Visual C# 2005 Express Edition:

http://msdn.microsoft.com/vstudio/express/visualcsharp/default.aspx

It's not as fully featured as VS Pro, for example, but it's free :)

--
Dave Sexton
http://davesexton.com/blog

Nikola Skoric said:
dave@jwa said:
Hi Nikola,
Could it be something with [OptionalField] being added to
standard later, so my version of framework and/or compiler doesn't
recognise it?

Yes! (Sorry I didn't think of that :)

OptionalFieldAttribute was added to the 2.0 framework.

Can I then just install 2.0 framework and everything's fine or do I have
to upgrade the VS too?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top