473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

The type or namespace name 'Collection' could not be found

I'm trying to compile myGeneration PropertyCollectionAll.cs file with VCS
Express 2005 bot got error

Error 1 The type or namespace name 'Collection' could not be found (are you
missing a using directive or an assembly reference?)
PropertyCollectionAll.cs 17 39

I looked to .NET 2 help and found that Collection class is included in
mscorlib so it doen't need assembly reference.
How to fix this error ?

Whole file which causes this error is:

using System;
using System.Xml;
using System.Collections;
using System.Data;
using System.Data.OleDb;

namespace MyMeta
{

public class PropertyCollectionAll : Collection, IPropertyCollection,
IEnumerable, IEnumerator, ICollection
{

public PropertyCollectionAll()
{

}

internal void Load(IPropertyCollection local, IPropertyCollection global)
{
this._local = local;
this._global = global;
}

#region IPropertyCollection
//[System.Runtime.InteropServices.DispId(0)]
public IProperty this[string key]
{
get
{
if(this._local.ContainsKey(key))
{
return this._local[key];
}
else if(this._global.ContainsKey(key))
{
return this._global[key];
}

return null;
}
}

/// <summary>
/// This method will either add or update a key value pair. If the key
already exists in the collection the value will be updated.
/// If this key doesn't exist the key/value pair will be added. If only
want to update, and not add new items, use <see cref="ContainsKey"/to
determine if the key already exists.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public IProperty AddKeyValue(string key, string value)
{
throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
}

/// <summary>
/// Removes a key/value pair from the collection, no error is thrown if
the key doesn't exist.
/// </summary>
/// <param name="key">The key of the desired key/value pair</param>
public void RemoveKey(string key)
{
throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
}

/// <summary>
/// Use ContainsKey to determine if a key exists in the collection.
/// </summary>
/// <param name="key">The key of the desired key/value pair</param>
/// <returns>True if the key exists, False if not</returns>
public bool ContainsKey(string key)
{
if(this._local.ContainsKey(key))
{
return true;
}
else if(this._global.ContainsKey(key))
{
return true;
}

return false;
}

/// <summary>
/// Removes all key/value pairs from the collection.
/// </summary>
new public void Clear()
{
throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
}
#endregion

#region IEnumerable Members

public IEnumerator GetEnumerator()
{
Reset();
return (this as IEnumerator);
}

#endregion

#region IEnumerator Members

public void Reset()
{
useLocalEnum = true;
wereDone = false;
_localEnumerator = this._local.GetEnumerator();
_globalEnumerator = this._global.GetEnumerator();
}

public object Current
{
get
{
IProperty prop = null;

if(useLocalEnum)
{
prop = (IProperty)_localEnumerator.Current;
}
else
{
prop = (IProperty)_globalEnumerator.Current;
}

return prop;
}
}

public bool MoveNext()
{
if(this.useLocalEnum)
{
if(_localEnumerator.MoveNext()) return true;
}

if(!wereDone)
{
this.useLocalEnum = false;

while(true)
{
if(_globalEnumerator.MoveNext())
{
IProperty prop = (IProperty)_globalEnumerator.Current;

if(!this._local.ContainsKey(prop.Key))
{
return true;
}
}
else
{
break;
}
}

wereDone = true;
}

return false;
}

#endregion

#region ICollection Members

public new bool IsSynchronized
{
get
{
// TODO: Add Databases.IsSynchronized getter implementation
return false;
}
}

public new void CopyTo(Array array, int index)
{
// TODO: Add Databases.CopyTo implementation
}

public new object SyncRoot
{
get
{
// TODO: Add Databases.SyncRoot getter implementation
return null;
}
}

#endregion

private IPropertyCollection _local;
private IPropertyCollection _global;

bool useLocalEnum = true;
bool wereDone = false;
private IEnumerator _localEnumerator = null;
private IEnumerator _globalEnumerator = null;
}
}

Jul 20 '07 #1
2 29952
The Collection<Tclass is in the System.Collections.ObjectModel
namespace, not in System.Collections.

Also, for your implementation of IEnumerable, I would highly recommend
using yield statements to generate your iterators. It will simplify your
code tremendously.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrus" <ko********@hot.eewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I'm trying to compile myGeneration PropertyCollectionAll.cs file with VCS
Express 2005 bot got error

Error 1 The type or namespace name 'Collection' could not be found (are
you missing a using directive or an assembly reference?)
PropertyCollectionAll.cs 17 39

I looked to .NET 2 help and found that Collection class is included in
mscorlib so it doen't need assembly reference.
How to fix this error ?

Whole file which causes this error is:

using System;
using System.Xml;
using System.Collections;
using System.Data;
using System.Data.OleDb;

namespace MyMeta
{

public class PropertyCollectionAll : Collection, IPropertyCollection,
IEnumerable, IEnumerator, ICollection
{

public PropertyCollectionAll()
{

}

internal void Load(IPropertyCollection local, IPropertyCollection global)
{
this._local = local;
this._global = global;
}

#region IPropertyCollection
//[System.Runtime.InteropServices.DispId(0)]
public IProperty this[string key]
{
get
{
if(this._local.ContainsKey(key))
{
return this._local[key];
}
else if(this._global.ContainsKey(key))
{
return this._global[key];
}

return null;
}
}

/// <summary>
/// This method will either add or update a key value pair. If the key
already exists in the collection the value will be updated.
/// If this key doesn't exist the key/value pair will be added. If only
want to update, and not add new items, use <see cref="ContainsKey"/to
determine if the key already exists.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public IProperty AddKeyValue(string key, string value)
{
throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
}

/// <summary>
/// Removes a key/value pair from the collection, no error is thrown if
the key doesn't exist.
/// </summary>
/// <param name="key">The key of the desired key/value pair</param>
public void RemoveKey(string key)
{
throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
}

/// <summary>
/// Use ContainsKey to determine if a key exists in the collection.
/// </summary>
/// <param name="key">The key of the desired key/value pair</param>
/// <returns>True if the key exists, False if not</returns>
public bool ContainsKey(string key)
{
if(this._local.ContainsKey(key))
{
return true;
}
else if(this._global.ContainsKey(key))
{
return true;
}

return false;
}

/// <summary>
/// Removes all key/value pairs from the collection.
/// </summary>
new public void Clear()
{
throw new NotImplementedException("Cannot call AddKeyValue on this
collection");
}
#endregion

#region IEnumerable Members

public IEnumerator GetEnumerator()
{
Reset();
return (this as IEnumerator);
}

#endregion

#region IEnumerator Members

public void Reset()
{
useLocalEnum = true;
wereDone = false;
_localEnumerator = this._local.GetEnumerator();
_globalEnumerator = this._global.GetEnumerator();
}

public object Current
{
get
{
IProperty prop = null;

if(useLocalEnum)
{
prop = (IProperty)_localEnumerator.Current;
}
else
{
prop = (IProperty)_globalEnumerator.Current;
}

return prop;
}
}

public bool MoveNext()
{
if(this.useLocalEnum)
{
if(_localEnumerator.MoveNext()) return true;
}

if(!wereDone)
{
this.useLocalEnum = false;

while(true)
{
if(_globalEnumerator.MoveNext())
{
IProperty prop = (IProperty)_globalEnumerator.Current;

if(!this._local.ContainsKey(prop.Key))
{
return true;
}
}
else
{
break;
}
}

wereDone = true;
}

return false;
}

#endregion

#region ICollection Members

public new bool IsSynchronized
{
get
{
// TODO: Add Databases.IsSynchronized getter implementation
return false;
}
}

public new void CopyTo(Array array, int index)
{
// TODO: Add Databases.CopyTo implementation
}

public new object SyncRoot
{
get
{
// TODO: Add Databases.SyncRoot getter implementation
return null;
}
}

#endregion

private IPropertyCollection _local;
private IPropertyCollection _global;

bool useLocalEnum = true;
bool wereDone = false;
private IEnumerator _localEnumerator = null;
private IEnumerator _globalEnumerator = null;
}
}

Jul 20 '07 #2
I'm trying to compile myGeneration PropertyCollectionAll.cs file with
VCS Express 2005 bot got error

Error 1 The type or namespace name 'Collection' could not be found
(are you missing a using directive or an assembly reference?)
PropertyCollectionAll.cs 17 39

I looked to .NET 2 help and found that Collection class is included in
mscorlib so it doen't need assembly reference.
How to fix this error ?
It might not need an assembly reference, but you still need to specify a
namespace: either directly or with a 'using' clause.

By the way: did you mean the Collection< *generic* class or the one
in Microsoft.VisualBasic?

Hans Kesting
Jul 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Jorgensen | last post by:
I frequently find myself wanting to use class abstraction in VB/VBA code, and frankly, with the tacked-on class support in VB/VBA, there are some problems with trying to do that and have any...
2
by: Dave Leach | last post by:
I am writing a Windows MDI application in C#. I would like to cast an object to a specific type. I know that the object is of a compatible type. The code below shows what I would like to do, but...
1
by: Randall Parker | last post by:
Using VS 2003 and Cassini web server. I'm new to ASP.Net and so this may be a dumb question. I'm getting an error where the type 'FarmLand.WebForm1' is not found. The Codebehind C# source file...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
15
by: Paddy | last post by:
Hi, I am trying to work out why I get UnboundLocalError when accessing an int from a function where the int is at the global scope, without explicitly declaring it as global but not when accessing...
4
by: Dan Manges | last post by:
Given a type as a string, is there an easy way using reflection to find where it resides in the .NET framework? Example: Given "XmlNode", get "System.Xml" Given "ArrayList", get...
3
by: phil | last post by:
I have written a little application that can grab part of a page from a web site. I then want to take this result and be able to serialize it so that it can be stored as XML. I am storing these...
5
by: mknoll217 | last post by:
I am a newbie at XML. I have been given an xml document that I need to write the schema for, for a class assignment. The xml given to me is <?xml version="1.0"?> <Vendors> <Vendor> ...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.