473,320 Members | 1,694 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,320 software developers and data experts.

Namespace snags?

BH
Hi C# & .NET detectives,

can you help with two problems I've encountered lately?

1) These seem equivalent to me but one fails and the other doesn't.

This fails with "type or namespace 'Security' could not be found" message:
//-----------
using System;
using System.Threading;
//...later...
Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//--------------

However, this succeeds:
//----------
// using System ...code now uses explicit System reference
using System.Threading;
//...later...
System.Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//----------
2) OK, how about this problem
This fails with "type or namespace STAThread cannot be found" message...

[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

How do I use/refer to STAThread correctly?

Thanks for your time,

BH
Nov 15 '05 #1
4 1856
100
Hi BH,
The answer of your first question can be found in MSDN. The following is
quote from MSDN:
"... Create a using directive to use the types in a namespace without having
to specify the namespace. A using directive does not give you access to any
namespaces that may be nested in the namespace you specify. ..."

*Security* is a namespace.

About the second question. STAThreadAttribute class is defined in System
namespace.
You can either use fully qualified name:

[System.STAThread]
static void Main()
{
Application.Run(new MainForm());
}

or use *using* directive:

using System;

[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
HTH
B\rgds
100


can you help with two problems I've encountered lately?

1) These seem equivalent to me but one fails and the other doesn't.

This fails with "type or namespace 'Security' could not be found" message:
//-----------
using System;
using System.Threading;
//...later...
Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//--------------

However, this succeeds:
//----------
// using System ...code now uses explicit System reference
using System.Threading;
//...later...
System.Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//----------
2) OK, how about this problem
This fails with "type or namespace STAThread cannot be found" message...

[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

How do I use/refer to STAThread correctly?

Thanks for your time,

BH

Nov 15 '05 #2
BH,

The reason the first doesn't work is that using declarations do not act
as shortcuts for other namespaces, only for types that are within the
namespaces that you use in the "using" statements. So, you have to put
System.Security, etc, etc.

The reason that the STAThread attribute is not found is because you took
out the "using System;" directive, so it doesn't know which namespace
STAThread is in. If you place "using System;" back at the top, it will find
it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"BH" <bo*****@yahoo.com> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
Hi C# & .NET detectives,

can you help with two problems I've encountered lately?

1) These seem equivalent to me but one fails and the other doesn't.

This fails with "type or namespace 'Security' could not be found" message:
//-----------
using System;
using System.Threading;
//...later...
Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//--------------

However, this succeeds:
//----------
// using System ...code now uses explicit System reference
using System.Threading;
//...later...
System.Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//----------
2) OK, how about this problem
This fails with "type or namespace STAThread cannot be found" message...

[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

How do I use/refer to STAThread correctly?

Thanks for your time,

BH

Nov 15 '05 #3
BH
Thanks folks... problems solved, lessons learned.

BH

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:%2****************@TK2MSFTNGP10.phx.gbl...
BH,

The reason the first doesn't work is that using declarations do not act as shortcuts for other namespaces, only for types that are within the
namespaces that you use in the "using" statements. So, you have to put
System.Security, etc, etc.

The reason that the STAThread attribute is not found is because you took out the "using System;" directive, so it doesn't know which namespace
STAThread is in. If you place "using System;" back at the top, it will find it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"BH" <bo*****@yahoo.com> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
Hi C# & .NET detectives,

can you help with two problems I've encountered lately?

1) These seem equivalent to me but one fails and the other doesn't.

This fails with "type or namespace 'Security' could not be found" message: //-----------
using System;
using System.Threading;
//...later...
Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//--------------

However, this succeeds:
//----------
// using System ...code now uses explicit System reference
using System.Threading;
//...later...
System.Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//----------
2) OK, how about this problem
This fails with "type or namespace STAThread cannot be found" message...

[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

How do I use/refer to STAThread correctly?

Thanks for your time,

BH


Nov 15 '05 #4
If you would like to use Security to identify any of the types within the
System.Security namespace, you can implement your using line as: "using
Security = System.Security;". This also helps if you have to reference two
namespaces which have members with the same name, thus causing the compiler
to not be able to determine which type you mean.

Steve
"BH" <bo*****@yahoo.com> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl...
Thanks folks... problems solved, lessons learned.

BH

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
BH,

The reason the first doesn't work is that using declarations do not

act
as shortcuts for other namespaces, only for types that are within the
namespaces that you use in the "using" statements. So, you have to put
System.Security, etc, etc.

The reason that the STAThread attribute is not found is because you

took
out the "using System;" directive, so it doesn't know which namespace
STAThread is in. If you place "using System;" back at the top, it will

find
it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"BH" <bo*****@yahoo.com> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
Hi C# & .NET detectives,

can you help with two problems I've encountered lately?

1) These seem equivalent to me but one fails and the other doesn't.

This fails with "type or namespace 'Security' could not be found" message: //-----------
using System;
using System.Threading;
//...later...
Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//--------------

However, this succeeds:
//----------
// using System ...code now uses explicit System reference
using System.Threading;
//...later...
System.Security.Principal.IPrincipal user = Thread.CurrentPrincipal;
//----------
2) OK, how about this problem
This fails with "type or namespace STAThread cannot be found" message...
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}

How do I use/refer to STAThread correctly?

Thanks for your time,

BH



Nov 15 '05 #5

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

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
25
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
6
by: Don Wash | last post by:
Hi There! I just need some advice on Namespace management for creating reusable VB.NET applications. I would like my applications to have this namespace structure... Namespace MyCompany ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
2
by: puzzlecracker | last post by:
after reading some of the post I found out something rather radical to my previous understanding: that when you do #include<iostream> #include<string> #include<vector> etc compiler puts...
6
by: clinton__bill | last post by:
Hi, I usually use "using namespace <namespace_name>" to reference a namespace. Today I run across a code, in its header file it has this, namespace SP1{ class C1; } While SP1::C1 is a...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
14
by: Tiraman | last post by:
Hi , I would like to use nested namespace . I have 3 namespace as dll's : Namespace A Namespace B Namespace C And i want to have some namespace that contain them all , some thing like
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.