.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links


Posted By:      Posted Date: August 31, 2010    Points: 0   Category :ASP.Net
Hi,A rather basic question coming up, but it does say no question too simple.I am coding for the first time in .net and looking at namespaces and classes.  If had a look on the web but I'm still not totally clear on right approach to structuring them.For instance:If I have 2 classes, called EmailTemplate and EmailSender, how would I structure this?  Do I do this...in the first class namespace Email { class EmailSender { } } then in the second class namespace Email { class EmailTemplate { } } or am I getting it totally wrong?Any advice would be apprceciatedJohn

View Complete Post

More Related Resource Links

Security: Protect Private Data with the Cryptography Namespaces of the .NET Framework


The .NET Framework includes a set of cryptographic services that extend the services provided by Windows through the Crypto API. In this article, the author explores the System.Security.Cryptography namespace and the programming model used to apply cryptographic transformations. He discusses reasons why cryptography is easier in .NET than it was before, including the easy programmatic acccess developers have to the cryptography APIs and the difference between symmetric and asymmetric algorithms. Along the way, a brief discussion of the most widely used algorithms, including RSA, DSA, Rijndael, SHA, and other hash algorithms, is provided.

Dan Fox

MSDN Magazine June 2002

V1.1 to Beta 2 - Namespaces Not Recognized


We are attempting to test out a website written in VS2003/.Net 1.1 in VS2005 Beta 2/.Net 2.0.  Our main problem at this point is that certain classes are not being recognized when they are referenced in other files not in the same directory as the class file.


A Framework.cs file under \Applications is inherited by several other webpages. It resides under the namespace Company.WebSite.Applications.

Another class, SearchHistories, is in \Applications\CrackHistory directory. The namespace of SearchHistories class is Company.WebSite.Applications.CrackHistory. SearchHistories inherits Framework.  Under .NET1.1, there was no problem with this. However, in VS2003, a compile error states "The type or namespace name 'Framework' could not be found (are you missing a using directive or an assembly reference?) C:\WEB\Applications\CrackHistory\SearchHistories.aspx.cs".

The immediate solution is to copy the Framework.cs file from the Applications directory and copy it into the Applications\CrackHistory directory. Then the error goes away. What is up with that?

Removing Xml Namespaces from XmlSerialization

I am currently using Xml Serialization to serialize my classes in Visual Studio 2010, but I have been unable to remove the default namespaces that get attached to my document. These two elements get attached to the root of my document each time. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" When I specify my XmlRoot attribute on my class, I have tried both methods: [XmlRoot("requestor", Namespace="")] as well as <pre lang="x-c#">[XmlRoot("requestor")] Both of these methods have continued to result in the namespace being appended to my XmlDocument. This is currently the method I have been calling for my Xml Serialization: <pre lang="x-c#">/// <summary> /// Performs XmlSerialization of a particular object/class /// using the .Net Xml Serializer /// </summary> /// <param name="objForSerialization">object or class instance to be serialized</param> /// <returns>string containing the serialized object in Xml Document format</returns> public static string XmlSerialize(object objForSerialization) { string strSerialized = string.Empty; using (MemoryStream memoryStream = new MemoryStream()) { XmlSerializer serializer = new XmlSerializer(objFo

Resource is ambiguous,imported from the namespaces or types 'System,System.web

Hi, I have one project in TFS and once i get latest version it gives following error. "Resource is ambiguous,imported from the namespaces or types 'System,System.web'"   Even i have checked twice that there is no duplication but still giving error.   Please help me on same. Thanks in advance 

Deserialization of XML containing nested namespaces into an object


If I've an XML which has nested namespaces, how should I deserialize it into an object? It's not throwing an exception but the values are getting lost.



XmlSerializer xmlSerializer = new XmlSerializer

Problems with Schema Collection and Namespaces


Our company is going to start exchanging XML documents and I'm trying to understand how to correctly use XML data types in SQL Server 2005.

There is a published xsd which I think I'm supposed to store in a Schema Collection so that Sql Server can use it to validate typed XML variables and columns.
There also are some examples XML documents available for testing.

Because the xsd and the samples are relatively huge (1-2 megabytes each),  I have distilled both down to the minimum necessary fields both for my own sanity while testing and for use in examples to forums such as this.

I believe I am down to my last problem which centers on understanding namespaces.

The actual XML documents do not and will not have any namespace parameters within them.
But I am only able to succesfully validate my testing samples when I include an xmlns parameter.
What am I doing wrong?
How can I get a sample without an xmlns parameter to successfully validate?

Here is what I have:

USE LSExport

IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE [name] = 'MyPrivateSchemaCollection')
 DROP XML SCHEMA COLLECTION dbo.MyPrivateSchemaCollection

DECLARE @testSchema XML
SET @testSchema =
'&lt;?xml version="1.0" encoding="UTF-8"?&gt;

Creating Namespaces


 Hello everyone and thanks for your help in advance.  I am building an ASP.Net application and want to use Namespaces for the first time.  Within an App_Code folder, I have created three classes called RewriteContext, RewriteModule, and RewriteHandler.  Each begins with:

Namespace RewriteModule

    Public Class (Class Name)


However, if I understand what I am doing correctly, I should be able to do something like

Dim myClass As New RewriteModule.RewriteContext or

Dim myClass As New RewriteModule.RewriteHandler or

Dim myClass As New RewriteModule.RewriteModule

However, Intellisense only picks up Dim myClass As New RewriteModule.RewriteContext.  I'm not really sure why that would be.  Any insight would be greatly appreciated.


Classes and Namespaces - Error CS0101 the namespace already contains a definition for


I keep getting the error: Error message: CS0101: The namespace '<global namespace>' already contains a definition for 'checkvalue'.

Then, I rename the Inherits from the @page directive in both the .aspx and .aspx.cs pages and it works!

My website has only 2 pages, and both use the same class (same class name, exactly same syntax) but it has been copied and pasted and the 2 aspx pages (and aspx.cs pages) are not referencing each other.

In other words, both aspx.cs pages (called page1.aspx.cs and page2.aspx.cs) has the class

public class CheckValue
        return true;

Both the aspx pages reference the 'inherits' files seperately:

<%@ Page Language="C#" CodeFile="page1.aspx.cs" Inherits="_1" %>

and my code behind

public partial class _1 : System.Web.UI.Page

and for my second page

<%@ Page Language="C#" CodeFile="page2.aspx.cs" Inherits="_2" %>

and my code behind

public partial class _2 : System.Web.UI.Page

I don't use the .resx file.

Why does this error happen some times, and not other times?


How do I handle multiple namespaces?



I have an XML document that has multiple namespaces. I cannot figure out how to successfully get data out of this thing. The following:

DECLARE @xml xml = '<?xml version="1.0"?>
<Messages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.net/MyCompany.Comms.Commands" xmlns:baseType="MyCompany.Api.Command">
SELECT	@xml.query(

Can I opt to ignore namespaces?



I am using XML functions in T-SQL to parse a series of XML document. The trouble is that these messages can have one of a range of namespaces and there is no way of knowing ahead of time which namespace is being used as the default. Hence I have some code that looks like this:

DECLARE @vMessageType NVARCHAR(128);
SET @vMessageType = @pMessage.value('declare default element namespace "http://tempuri.net/namespace1";
IF @vMessageType = ''
	SET @vMessageType = @pMessage.value('declare default element namespace "http://tempuri.net/namespaec2";	local-name((/Messages/*[1])[1])','nvarchar(128)');
IF @vMessageType = ''
	SET @vMessageType = @pMessage.value('declare default element namespace "http://tempuri.n
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend