when I add a new class to the project, all the other goes wrong.

M

mathphoenix

I have a csharp project develop with vs2008, it can pass build first,
when I add a new class to it, the other class in the project can't pass the
compiler check, I can't check the new class now, It seem that all go wrong.
anyone meet the trouble?

Another question, is that different the using direction inside or beside
the namespace ?
 
M

Morten Wennevik [C# MVP]

Hi,

You really need to give us more information than this, especially the exact
errors you get. If the project can't pass the compiler check there should be
compiler errors/warnings.

The 'using' keyword serves two purposes.

using System.IO;

namespace MyNamespace
{
// You can here type File instead of the full System.IO.File
}

Inside a method it serves the IDisposable interface and will automatically
call Dispose

void MyMethod()
{
using(StreamWriter sw = new StreamWriter("C:\\MyFile.txt"))
{
sw.WriteLine("Hello World");
}
}

when the using block ends it will call sw.Dispose(), which in turn will
Flush and Close the StreamWriter as well.
 
P

Pavel Minaev

   Another question, is that different the using direction inside or beside
the namespace ?

If you mean the difference between:

using System;
namespace Foo {
...
}

and

namespace Foo {
using System;
...
}

then yes, there is a subtle difference there for the single-namespace-
in-a-file case, when it comes to dealing with classes in the global
namespace. I'll just illustrate with code:

// Outside of any namespace
class Foo { ... }
namespace Bar { class Foo { ... } }

using Bar;
namespace Test1 {
using F = Foo; // Foo here is global::Foo
}

namespace Test2 {
using Bar;
using F = Foo; // Foo here is Bar.Foo
}

Basically, the way it works is this: it looks for the identifier in
scopes starting from the innermost one and going outside; and, for
each scope, it _first_ looks for identifiers declared in that scope
(i.e. in the same namespace, for a namespace), and only then looks in
namespaces referenced by "using" directives within that scope.

In practice, since common coding style is to avoid out-of-namespace
declarations, this difference is hardly ever observed.

For the case of multiple namespaces in a file, the difference is more
pronounced, but should be fairly obvious.
 
M

mathphoenix

some more detail, I have use c# for many yeas, I understand the concept, I
think it may be bug of visual studio 2008?
I am doing some refractor of dotnetnuke(the edition 4.09) for my own
purpose.
one file which can pass check before like this:

namespace DotNetNuke.Services.Vendors
{
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;

using System;
using System.Collections;
using System.Runtime.CompilerServices;

public class BannerController
{
public void AddBanner(BannerInfo objBannerInfo)
{
DataProvider.Instance().AddBanner(objBannerInfo.BannerName,
objBannerInfo.VendorId, objBannerInfo.ImageFile, objBannerInfo.URL,
objBannerInfo.Impressions, objBannerInfo.CPM, objBannerInfo.StartDate,
objBannerInfo.EndDate, objBannerInfo.CreatedByUser,
objBannerInfo.BannerTypeId, objBannerInfo.Description,
objBannerInfo.GroupName, objBannerInfo.Criteria, objBannerInfo.Width,
objBannerInfo.Height);
}

......
}
}


Now, i was told that error CS0234: “Utilities†is not exists in namespace
“DotNetNuke.DotNetNuke.Commonâ€(miss some reference?) ,

In my opinion, no matter which file I add to this project, the error is
misleading, and should be a bug, or it's my fault?

The project's default namespace is DotNetNuke, and I think it's nothing
about the using directive , isn't it?
 
M

Morten Wennevik [C# MVP]

I have seen cases where the error message is comletely irrelevant to the
actual error, as well as cases where it just simply says build failed with no
error messages or warnings at all (turned out it didn't like two vs instances
with a database project in each solution). It is apparantly unable to
understand Utilities, but the reason may not be so obvious. As you have put
it as a using directive the most likely cause would be that you are not
referencing the project/assembly containing the DotNetNuke.Common.Utilities
classes.

In your code, if you have at least one class with the namespace
DotNetNuke.Common.Utilities in a referenced project the code should compile.
There may be an error if you at the same time have a Utilities class in
DotNetNuke.Common but the error message should in that case indicate that
Utilities already exists.

I assume you do have a class with this namespace, so there may well be a
bug. Try removing the using directive referring to Utilities and instead use
the full class name for BannerInfo and/or DataProvider. If this works, try
deleting the namespace part from BannerInfo/DataProvider and see if Visual
Studio is able to figure out where these classes are defineed (ALT+F10 when
the cursor is on the class name).

As for using directives inside or outside the namespace. I don't think it
matters at all as long as they are outside the class scope.

If you are able to reproduce the error in a new solution you can submit a
bug report at the Microsoft Developer Division Feedback Center

https://connect.microsoft.com/VisualStudio
(You may need to sign in to be able to submit a bug)

If you rather want me to submit the bug, send me a project where this bug is
reproducable and I'll be happy to submit a bug report.
 
J

Jesse Houwing

Hello Morten Wennevik [C# MVP],

One other thing that comes to mind... Are you by any chance adding a file
called utilities.cs to the project? Or some other named class that corresponds
either with a namespace or a class elsewhere in your project?

Jesse
 
M

mathphoenix

Thanks for all replies.
This project is submit to codeplex, and it's far from ctp, you can just
download the code from
http://mathphoenix.codeplex.com/SourceControl/ListDownloadableCommits.aspx
I know Microsoft connector, but I am not good at English, it's a little
hard to describe clear by English for me, I am very glad if you can help me.
After download, it's easy to reproduce the problem, expand the DotNetNuke
project, open the DotNetNuke.Common directory and exclude Initialize.cs form
project, and you can pass build the DotNetNuke project, I am refractor the
solution, so you can't compiler all the project, just the DotNetNuke project
is enough for the purpose.
Some backgroud about this project:
This project is C# edition for dotnetnuke version 4.09, I use refractor
to get C# the code from debug assemble, and if I meet trouble to understand
the code, I will look back of the vb implement.
I use visual studio macro and my own VB2CS project to develop or modify
some VB function which now written by c#, this software is develop for mono
platform, so I hope all code just depend on mono and C#, I don't like to see
even one line vb code.
Because this project is not publish now, and you can just get the code
from source control, use the changset 16167 is the write one.
You may meet trouble that I am not sure weather you will meet some
Chinese character, I am sorry for this.
Thanks again.

Morten Wennevik said:
I have seen cases where the error message is comletely irrelevant to the
actual error, as well as cases where it just simply says build failed with
no
error messages or warnings at all (turned out it didn't like two vs
instances
with a database project in each solution). It is apparantly unable to
understand Utilities, but the reason may not be so obvious. As you have
put
it as a using directive the most likely cause would be that you are not
referencing the project/assembly containing the
DotNetNuke.Common.Utilities
classes.

In your code, if you have at least one class with the namespace
DotNetNuke.Common.Utilities in a referenced project the code should
compile.
There may be an error if you at the same time have a Utilities class in
DotNetNuke.Common but the error message should in that case indicate that
Utilities already exists.

I assume you do have a class with this namespace, so there may well be a
bug. Try removing the using directive referring to Utilities and instead
use
the full class name for BannerInfo and/or DataProvider. If this works,
try
deleting the namespace part from BannerInfo/DataProvider and see if Visual
Studio is able to figure out where these classes are defineed (ALT+F10
when
the cursor is on the class name).

As for using directives inside or outside the namespace. I don't think it
matters at all as long as they are outside the class scope.

If you are able to reproduce the error in a new solution you can submit a
bug report at the Microsoft Developer Division Feedback Center

https://connect.microsoft.com/VisualStudio
(You may need to sign in to be able to submit a bug)

If you rather want me to submit the bug, send me a project where this bug
is
reproducable and I'll be happy to submit a bug report.

--
Happy Coding!
Morten Wennevik [C# MVP]


mathphoenix said:
some more detail, I have use c# for many yeas, I understand the concept,
I
think it may be bug of visual studio 2008?
I am doing some refractor of dotnetnuke(the edition 4.09) for my own
purpose.
one file which can pass check before like this:

namespace DotNetNuke.Services.Vendors
{
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;

using System;
using System.Collections;
using System.Runtime.CompilerServices;

public class BannerController
{
public void AddBanner(BannerInfo objBannerInfo)
{
DataProvider.Instance().AddBanner(objBannerInfo.BannerName,
objBannerInfo.VendorId, objBannerInfo.ImageFile, objBannerInfo.URL,
objBannerInfo.Impressions, objBannerInfo.CPM, objBannerInfo.StartDate,
objBannerInfo.EndDate, objBannerInfo.CreatedByUser,
objBannerInfo.BannerTypeId, objBannerInfo.Description,
objBannerInfo.GroupName, objBannerInfo.Criteria, objBannerInfo.Width,
objBannerInfo.Height);
}

.....
}
}


Now, i was told that error CS0234: “Utilities†is not exists in
namespace
“DotNetNuke.DotNetNuke.Commonâ€(miss some reference?) ,

In my opinion, no matter which file I add to this project, the error is
misleading, and should be a bug, or it's my fault?

The project's default namespace is DotNetNuke, and I think it's nothing
about the using directive , isn't it?
 
M

mathphoenix

I am sorry for that it's my fault.
I think I know what's wrong, it's the file which I add to the project:


using System;
using System.Security;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.IO;
using DotNetNuke.Services.Log.EventLog;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Entities.Portals;
using System.Collections;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Common;
using System.Threading;
using DotNetNuke.Services.Scheduling;
using VB2CS;
using System.Web.Hosting;


namespace DotNetNuke.DotNetNuke.Common
{

public class Initialize
{
........
}




}

I forgot to remove the default namespace. it's the fundamental reason?

Although I can't understand why the ide was confuse by this simple mistake,
maybe is a big one :)?

it's possible to reproduce the error by a simple project, but not which I am
working for, it's a huge solution and it's not suitable to illustrate the
problem.

I don't have extern time, may be you can send this bug(maybe it's not a bug)
to Microsoft connector.

even the ide told me the class is not exist, I'm sure she know it, because
the class is highlight:)

I am sorry to waste you time just because my careless mistake.

thanks for all replies

--
Code Your Life
mathphoenix



Morten Wennevik said:
I have seen cases where the error message is comletely irrelevant to the
actual error, as well as cases where it just simply says build failed with
no
error messages or warnings at all (turned out it didn't like two vs
instances
with a database project in each solution). It is apparantly unable to
understand Utilities, but the reason may not be so obvious. As you have
put
it as a using directive the most likely cause would be that you are not
referencing the project/assembly containing the
DotNetNuke.Common.Utilities
classes.

In your code, if you have at least one class with the namespace
DotNetNuke.Common.Utilities in a referenced project the code should
compile.
There may be an error if you at the same time have a Utilities class in
DotNetNuke.Common but the error message should in that case indicate that
Utilities already exists.

I assume you do have a class with this namespace, so there may well be a
bug. Try removing the using directive referring to Utilities and instead
use
the full class name for BannerInfo and/or DataProvider. If this works,
try
deleting the namespace part from BannerInfo/DataProvider and see if Visual
Studio is able to figure out where these classes are defineed (ALT+F10
when
the cursor is on the class name).

As for using directives inside or outside the namespace. I don't think it
matters at all as long as they are outside the class scope.

If you are able to reproduce the error in a new solution you can submit a
bug report at the Microsoft Developer Division Feedback Center

https://connect.microsoft.com/VisualStudio
(You may need to sign in to be able to submit a bug)

If you rather want me to submit the bug, send me a project where this bug
is
reproducable and I'll be happy to submit a bug report.

--
Happy Coding!
Morten Wennevik [C# MVP]


mathphoenix said:
some more detail, I have use c# for many yeas, I understand the concept,
I
think it may be bug of visual studio 2008?
I am doing some refractor of dotnetnuke(the edition 4.09) for my own
purpose.
one file which can pass check before like this:

namespace DotNetNuke.Services.Vendors
{
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;

using System;
using System.Collections;
using System.Runtime.CompilerServices;

public class BannerController
{
public void AddBanner(BannerInfo objBannerInfo)
{
DataProvider.Instance().AddBanner(objBannerInfo.BannerName,
objBannerInfo.VendorId, objBannerInfo.ImageFile, objBannerInfo.URL,
objBannerInfo.Impressions, objBannerInfo.CPM, objBannerInfo.StartDate,
objBannerInfo.EndDate, objBannerInfo.CreatedByUser,
objBannerInfo.BannerTypeId, objBannerInfo.Description,
objBannerInfo.GroupName, objBannerInfo.Criteria, objBannerInfo.Width,
objBannerInfo.Height);
}

.....
}
}


Now, i was told that error CS0234: “Utilities†is not exists in
namespace
“DotNetNuke.DotNetNuke.Commonâ€(miss some reference?) ,

In my opinion, no matter which file I add to this project, the error is
misleading, and should be a bug, or it's my fault?

The project's default namespace is DotNetNuke, and I think it's nothing
about the using directive , isn't it?
 

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