System namespace(s) problem

  • Thread starter Thread starter Herby
  • Start date Start date
H

Herby

I seem to be having a problem with System namespace.
There seem to two System namepaces when viewing through Object browser
within .NET 2005.
One global System::
Then one under <mscorlib>

Each is different, having different sets of classes and some in common.
Why is this?

My project needs to reference the ones from <mscorlib> and not the
other.
How do i correct this?
 
Ok i understand now that namespaces are shared across system.dll and
mscorlib.dll etc
E.g.

System::Collections::

Where a namespace is shared each will have a unique set of classes(I
assume) why has it been split like this?

My problem my project does not seem to have full access to all the
classes in each
For example I am unable to reference

System::Diagnostics::Debug::Assert( mKeys.Count == mValues.Count );

error C3083: 'Debug': the symbol to the left of a '::' must be a type

This is defined in mscorlib.dll

But am referencing List<T>

also defined in mscorlib.dll

Whats going on here?
 
Herby said:
Ok i understand now that namespaces are shared across system.dll and
mscorlib.dll etc
E.g.

System::Collections::

Where a namespace is shared each will have a unique set of classes(I
assume) why has it been split like this?

My problem my project does not seem to have full access to all the
classes in each
For example I am unable to reference

System::Diagnostics::Debug::Assert( mKeys.Count == mValues.Count );

System.Diagnostics is in System.dll, not mscorlib.dll.

The main help topic for each class lists the assembly where the class is
defined, so there's no need to guess or hunt.

-cd
 
Where is List<T> defined?

What if i want to use classes from mscorlib.dll am i then expected to
do the following:
#import<mscorlib.dll>

Is this being secrectly done for System.dll too?



Im also having another problem:

CString mfc_str("Hello .NET");

// I have to qualify this due to another lib without a namespace having
a String class

System::String^ man_str = gcnew System::String( mfc_str);

I get the following error:

error C2440: 'initializing' : cannot convert from 'CString' to
'wchar_t'
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called

If i pass the MFC string to another module as a parameter and inside do
the same conversion then its fine!


In another dummy project with MFC this conversion is fine without
parameter passing.

What is the problem?
 
Herby said:
Where is List<T> defined?

RTFM, man...
What if i want to use classes from mscorlib.dll am i then expected to
do the following:
#import<mscorlib.dll>

No you don't. You want to

#using said:
Is this being secrectly done for System.dll too?

No, you need to

#using said:
Im also having another problem:

I can't help you with MFC problems. Hopefully someone else will respond to
that part.

-cd
 
Something is wrong
Why would i get the following error

error C3225: generic type argument for 'TKey' cannot be 'System::Char
^', it must be a value type or a handle to a reference type

When i have the following declaration:

Dictionary<System::String^, RuntimeMap^> mMap;
 
Herby said:
Something is wrong
Why would i get the following error

error C3225: generic type argument for 'TKey' cannot be 'System::Char
^', it must be a value type or a handle to a reference type
Char^ is not a value type, but a boxed value type. System::Char is
the name of the value type (or only char)
When i have the following declaration:

Dictionary<System::String^, RuntimeMap^> mMap;
The error message doesn't make sense for that declaration.
Are you sure you've quoted the correct line of code?

-hg
 
Holger Grund said:
Char^ is not a value type, but a boxed value type. System::Char is
the name of the value type (or only char)
Actually, that should be wchar_t not char.

-hg
 
Herby said:
Im also having another problem:

CString mfc_str("Hello .NET");

// I have to qualify this due to another lib without a namespace having
a String class

System::String^ man_str = gcnew System::String( mfc_str);
AFAICT, that should work just fine.

As I understand, this should call the String::String( signed char* ) ctor
(assuming you're not compiling with /D_UNICODE, in which case
the wchar_t* overload would be selected).
CString has a conversion to const char* which should be OK for
the conversion.
I get the following error:

error C2440: 'initializing' : cannot convert from 'CString' to
'wchar_t'
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called
That doesn't make sense. It sounds like you're using a ctor overload
with more than one parameter. In that case the first argument type is
a wchar_t for all overloads.

Are you sure, that this is the exact source line and the full diagnostic
message?

-hg
 
Thanks Holger.

I can assure you i am showing you the right lines of code.
I know it does not make sense, something else is causing these
problems, my hunch is its something to do with the include files.
If i compile the class containing these data members then compiles
fine.
If i compile a client of this class then thats when i get the errors.
Before i went into a painstaking lenghty investigation, i just wondered
if anyone had a 'quick' get out.

I can get around this for the moment via using the following:

ArrayList mKeys;
List<RuntimeMap^> mValues;

Rather than using the much more expressive:

Dictionary<String^, RuntimeMap^> mMap;
 
RTFM, man...

WFM, man? (What *** Manual?). (hehe) VS doesn't come with any manuals, and
MSDN2 is a very poor manual due to the way it organizes the info.

The actual VS.NET product is pretty cool, but trying to use it is severely
hampered by MSDN2 documentation that is organized so that you almost have to
already know the answer to look it up!

For example. I've been trying to figure out how to use a .cur file as a
cursor, and how to use a bitmap constructed at runtime as a cursor. These
sound like easy tasks, right? Especially since .cur files are made
specifically to be used as cursors. But I've been looking ALL MORNING for
how to make use of .cur file, and the info on MSDN2 shows an example which
compiles, but doesn't execute. And it gives instructions on how to embed a
..cur file into one's project that refer to elements of the IDE that don't
exist. Here is a link and a quote from that page:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.cursor.aspx

// In Visual Studio:
// 1. Select the cursor file in the Solution Explorer
// 2. Choose View->Properties.
// 3. In the properties window switch "Build Action" to "Embedded"

There is no "Properties" under the View menu (but there is "Property Page").
There is no "Build Action" in the Properties Page window. And the code line
they provide:

this->Cursor = gcnew System::Windows::Forms::Cursor( GetType(),
"cursor.cur" ) ;

compiles, but when run generates a null pointer exception (another
annoyance, why doesn't this report WHAT was null? Or in the case of
re-definitions, how about telling us in the error message WHAT was
multiply-defined? These ommisions cost us programmers HOURS when the system
should be able to give us this info immediately. But I digress...).

So the only example given doesn't work. So how am I suppose to figure out
how to do this? Of course the programmers at MS can just ask the team that
created the language. We consumers are stuck with zero documentation and a
reference where the info is outdated, sometimes occuring with multiple
entries some of which no longer apply and act as decoy traps, and that can't
be counted on to have sample code (especially in C++), and often lists code
samples that don't work.

This is why I ask so many (stupid) questions in this newsgroup to figure out
how to do the most basic things... : )

Whenever I ask 'why is there no C++ sample code?' the typical response is it
would be too much trouble for MS to make sample code for everything. So I
guess they never tested this software in C++, or else such sample code MUST
exist. And, come on! MS spends all this work to make a feature and its too
much trouble to show us how to use it? Then why isn't it too much trouble to
make the feature in the first place? What I'd really like to know is this:

WHAT IS MS's MINDSET ON HOW WE ARE SUPPOSE TO LEARN THEIR PRODUCTS WITHOUT
REASONABLE DOCUMENTATION?

I'm hoping this isn't true, but it sometime seems this info is made
intentionally difficult to access so that MS will have an advantage with
their own software over those who purchase it from them. This is VERY
frustrating from a consumer pov...

[==P==]
 
Back
Top