.NET (RSS)

.NET

.NET Passport SDK & IIS Issues

I installed the .NET Passport 2.5 SDK, to enable SSI on one of the portals I am developing. One good thing about version 2.5 of the SDK is that it has support for managed development in C#. I wanted to host this portal on my ASPXConnection webspace. Unfortunately ASPXConnection doesnt give access to some resources which may be required in special cases such as this. To install the Symmetric Key given by the Passport Services Manager, I needed command line accees to install the key.   :-(

I had installed the .NET Passport 2.5 SDK on my system and uninstalled the same after realizing that I would not be able to do this with my webspace. The next time hit F5 in VS.NET 2003 to run my web application, it said:

“Unable to start debugging on webserver”

I run the web application without debugging and it was ok. Conclusion was that my Web.config was ok. I didnt want to research for a very long time on this issue, so went ahead with the good old “KB306160”. I reinstalled the .NET Framework and everything was back to normal.


Update: Article 306172 seems to be a better place to start off, if you have ASP.NET & IIS issues

with 0 Comments

ASP.NET and IIS Problems

Quite a few times I have faced the problem of running ASP.NET web applications on my IIS.

The various errors which I used to get are:

  • “Cannot start ATL or COM debugging“
  • The webserver running your web application is in the Internet Zone
  • “Cannot start ASP.NET debugging on this webserver“

Every time I did a search for help on these topics, I landed on the respective Microsoft Knowledge Base Articles, which explain these problems in a nice manner. One such article is “Visual Studio .NET has detected Web server is not running ASP.NET 1.1”.

The problem with my IIS was this one:
3. Web Server specified by ASP.NET Web Project/Web Service Project is stopped or IP address cannot be mapped.
A: Please check IIS's Web configuration, include IP Address and working status. If your network IP address already changed, you must change your Web Site's IP Address. (If you use "localhost" to create Web Project, you can do nothing.)

All I did was changed the IP address configuration in IIS to 127.0.0.1. I did try to use localhost, but IIS doesnt take it. Once I did this, I was able to create ASP.NET applications. The next problem was that I wasnt able to run the ASP.NET web application because the URL of the web application ie. http://127.0.0.1/WebApp1 was in the InternetZone. The solution for this is given in the MSDN Library.

Tough these are some small issues, it would be a real pain if one does not know that the MSDN KB has solutions for all these.

with 0 Comments

TAPI functionality is not supported in the Managed World!

I had written a Dialer Application based on the Windows Phone Dialer that would pick-up numbers from a database and would dial 'em. From a CRM perspective, I also logged some stats about the telephone session. I did the coding in VB6 in the traditional way, by doing an API call to the tapiRequestMakeCall function of the “TAPI32.DLL”. My application would invoke the Phone Dialer and pass the phone number and callers name as the arguments. It works cool on Windows 98 and Windows 2000. I ran the same stuff on Windows XP. The Phone Dialer in XP is an updated one and supports both a Phone Call as well as an Internet Call. I need to prefix the numbers that I would be dialing by 0 (because I have a PBX). When I supply the parameter as “0, 24565687” as the number to be dialer, the dialer assumes that this is an internet call. I require the comma to introduce a delay before dialing the actual number because the PBX needs a second to switch to cease the PSTN line. This is quite irritating especially after I found out that when I dial the number manually in Phone Dialer (same number), it treats it as a Phone Number and does the job well.

With this problem, I thought that I will port my dialer to .NET. It all came to a halt when I found this KB article, which says that TAPI functionality cannot be implemented in managed code.

The reason:
Because of the complexity of the
TAPI 3.x Component Object Model (COM) interface, the managed wrapper that is created by Microsoft Visual Studio .NET does not work. Therefore, you cannot call TAPI functionality from managed code.

The solution:
COM Interop. Hmmm... There is always a solution. :-)

Interesting note:
All the TAPI 2.x data structures are based on the DWORD data type. TAPI 2.x also requires heavy use of pointers. Therefore, TAPI 2.x functionality is difficult to use from any language other than the Managed Extensions for C++. Offlate I have been reading about the Managed Extensions for C++, which is pretty cool.

with 0 Comments

Imagine Cup 2005 - "Imagine a world where technology dissolves the boundaries between us.."

Imagine Cup being one of the major global competitions for students hosted by Microsoft definitely draws the attention of anyone interest in computers, software, graphics and game programming.

I learnt about IC an year or more back that was when the IC 2003 was on. I hadnt worked on .NET at that time and I always thought that it is only for the geeks out there. "Change" is what is driving everything today. I saw the IC 2005 video when Mr.Tyson Dowd visited Bangalore and he spoke about IC '05. I still hadnt made-up my mind whether or not I should participate. Finally when the Round 1 dates for India was nearing, I teamed-up with Sabarish, Sharath and Deepthi Rao and we decided to get into it.

Round 1 is about a chess program, wherein we are given an
SDK and we are supposed to code for a function to find the checkmate move. It is definitely a good task to do but I felt that we are wasting time when we think of what participants in other countries would be doing. They would be working on their Software that would be submitted for the finals. We are stiil writing some crappy code for a chekmate. Phew...

After lots of discussion amongst ourselves we decided to start off with a brute-force method to get cracking with the program. After facing a hell lot of problems with MovePiceUnconditionally, we chaged our approach and now our program seems to be working fine except that it needs more tuning for performance. I read in the spoke "...so that you can save some precious nano seconds..." Oh. Please I wasnt thinking in nano seconds to compute the Checkmate in 1 move. The SDK is undoubtedly crappy in terms of ease-of-use, clarity and in some cases even the functionality.

Inspite of the fact that my exams are going on, I am not able to resist from "Spoking" (as in visitng theSpoke and Poke to see whats up). I also decided to make a program that will test the code that we write for different TestCases. After having some problems with loading different XML files (which contain the position of the different pieces) I finally have a working verion of the tester, which all of us will be using. It would also help our team to test for different cases and easily store & forward the results of the test.

One of the test cases:

<ChessGame>
<White>
<King HasMoved="True" Position="b7" />
<Knight HasMoved="True" Position="e7" />
<Knight HasMoved="True" Position="f6" />
</White>
<Black>
<King HasMoved="False" Position="d8" />
</Black>
</ChessGame>

theSpoke was hot with lots of discussions about whether or not people should 'openly' post the strategies that they are using in their solution and also some of them wanted to even post their DLLs!! Sriram said it right... Why dont they post the code itself if they want to really help someone?...

Lots happening for IC... India stands at No.2 in the number of registrations for IC too!
Yo!

with 2 Comments

Mike Tyson and C#

An interesting terminology that I came across while going through the C#LS was "boxing" and "unboxing". Though some may be familiar with these terms, I am new to it.

C# has a "unified type system". ie. all types including primitive ones derive from the type "object". A simple example would be:

class UTSDemo
{
 static void Main() {
  Console.WriteLine(333.ToString());
 }
}

The above sinppet calls the method ToString on the integer literal 333 which results in the output "333".

class Boxing
{
 static void Main() {
  int intVal1 = 123;
  object myObj = i;  // boxing
  int intVal2 = (int) myObj; // unboxing
 }
}

From the above example it is clear that an int value can be converted to an object and then back to an int. This is nothing but boxing and unboxing [Mike doesnt know this one ;-)] When a variable of a value type needs to be converted to a reference type, an object box is allocated to hold the value, and the value is copied into the box. Unboxing is just the opposite. When an object box is cast back to its original value type, the value is copied out of the box and into the appropriate storage location.

So using this you could write a method which has object type as its parameters or as the return type when you want to make the method general irrespective of the type.

with 1 Comments

SMTP access using VC#.NET

I developed the registration website for DWDN where I had to add a small functionality- when somebody registers for an event, an automated mail was to be sent to him/her to the email id specified during registration.

The harder way out was to use sockets and talk to the SMTP server directly and take the pains of handling various conditions. The simpler alternative is System.Web.Mail. The beauty of .NET lies in its feature-rich classes and the organized way in which everythings has been made available to the end-programmer.

The code was as simple as:

using System.Web.Mail;

MailMessage m=new MailMessage();
m.To=txtemail.Text;
m.Subject="Date with .NET : Registration Acknowledgment";
m.From="
xyz@gmail.com";
msg="Hello "+ mytitle + txtname.Text +"\n \n Your registration for the event: \n " + lblevent.Text + " is under process.\nYou will be receiving a confirmation mail.\n Please feel free to mail us on
xyz@gmail.com if you need any clarifications. \n Regards";
m.Body=msg;
SmtpMail.SmtpServer="localhost";//fill in the name of the SMTP mail server
SmtpMail.Send(m);//send the mail message

It provides properties and methods for sending messages using the Collaboration Data Objects for Windows 2000 (CDOSYS) message component. It can deliver mail through Win2000 SMTP mail service or any arbitrary mail server.

That’s cool enough. The site is hosted on WebMatrixHostitng and their server provides Authenticated-SMTP only. That’s because of their SPAM-control policy.

I had to add this extra bit of code into what I had done earlier.

m.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
m.Fields["
http://schemas.microsoft.com/cdo/configuration/sendusername"] = "myusername";
m.Fields["
http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "mypass";

Here comes the problem… I was using VS.NET 2002 and the “Fields” collection for the MailMessage class isn’t defined in 2002. :-( I had no other option but to install VS.NET 2003 and get going with it.

with 1 Comments

Very simple/basic concepts in C#

It is always better to understand these concepts with an example rather than trying to understand paragraphs of explanation.

Example:
class sharpTest
{
 static void Main() {
  string s = "Sunil";
  string t = string.Copy(s);
  Console.WriteLine(s == t);
  Console.WriteLine((object)s == (object)t);
 }
}

Output:
True
False

Inference:
Two expressions of type object are considered equal if both refer to the same object, or if both are null.
Two expressions of type string are considered equal if the string instances have identical lengths and identical characters in each character position, or if both are null.

Type conversions are similar to C++. Implicit conversions like int to long are done without any loss of data. Explicit conversions are done with a cast expression.

Arrays in C#
As usual, single-dimensional and multi-dimensional arrays are supported.

// Creates a single-dimensional array of 5 elements
int[] arr = new int[5];

What is to be noted is that arrays are also reference types and hence have to be explicitly allocate the memory by specifying the size of the array.

// Some more arrays
int[,,] a3;  // 3-dimensional array of int
int[][] j2;  // "jagged" array: array of (array of int)
int[][][] j3;  // array of (array of (array of int))


Type system unification
class Test
{
 static void Main() {
  Console.WriteLine(3.ToString());
 }
}
All types including value types are derived from the type object. It is possible to call object methods on any value, even values of “primitive” types such as int.

with 1 Comments

Types in C#

First time I saw the C# code in a magazine, I thought “Oh Damn it. Another new language, new syntax, new keywords…more confusion”. But now I don’t think so. C# is not completely different from other languages speaking of its syntax and approach. Moving further on, I learnt about the data types in C#.

C# supports two kinds of types: value types and reference types. No big deal. The name says it all. In case of values types, the variable stores the value directly and in case of reference types, it stores the reference to the variable (address). Other concepts like possibility of two variables referencing the same object are possible as in the case of C++.

A sample program to understand the types:

using System;
class ClassObj
{
 public int num = 0;
}

class ClassTest
{
 static void Main()
 {
  int x = 0;
  int y = x;
  y = 101;

  ClassObj ref1 = new ClassObj();
  ClassObj ref2 = ref1;
  ref2.num = 999;

  Console.WriteLine("Values: {0}, {1}", x, y);
  Console.WriteLine("Refs: {0}, {1}", ref1.num, ref2.num);
 }
}

C:\WINNT\Microsoft.NET\Framework\v1.0.3705>csc D:\cstypes.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

C:\WINNT\Microsoft.NET\Framework\v1.0.3705>cstypes
Values: 0, 101
Refs: 999, 999

An interesting thing that I’ve observed is the method used to print the formatted output in Console.WriteLine

Console.WriteLine takes a variable number of arguments. The first argument is a string, which may contain numbered placeholders like {0} and {1}. Each placeholder refers to a trailing argument with {0} referring to the second argument, {1} referring to the third argument, and so on. Before the output is sent to the console, each placeholder is replaced with the formatted value of its corresponding argument.

with 1 Comments

What is so sharp about C#?

I was going through a list of articles available on the INETA website. I came across an article with the heading “Why C # is sharp and why is VB.NET basic?” Hmmm… However, the author has no intentions of looking down upon VB. I have done quite a few projects in VB 6. I am still a VB enthusiast because what I like most about it, is its simplicity and ability to do amazing stuff with little effort (directly proportional to coding?? Ahem…).

A few days back, I had read an extensive comparison between 11 languages in the September 2004 edition of DIQ (Developer IQ http://www.developeriq.com). It was called “The Great Language Shootout”. The article tabulates the results with C# scoring an overall 68pts and Java landing at 65pts. The article also explains in detail about the evaluation process. These figures are clearly just indicators of a test process and cannot form the basis to decide the power and application of any language or its future.

Unable to resist the temptation, I decided to write a simple HelloWorld… nope not just World… HelloManagedWorld program in C#. Managed because, I’m using the .NET csc compiler.

The code:

using System;
class helloManagedWorld
{
 static void Main()
 {
  Console.WriteLine("Hello Managed World!");
 }
}

Some explanation:

The using System; directive references a namespace called System that is provided by the Microsoft .NET Framework class library. This namespace contains the Console class referred to in the Main method. Namespaces provide a hierarchical means of organizing the elements of one or more programs. A “using” directive enables unqualified use of the types that are members of the namespace. The “Hello Managed World!” program uses Console.WriteLine as shorthand for System.Console.WriteLine.

The Main method is a member of the class helloManagedWorld. It has the static modifier, and so it is a method on the class helloManagedWorld rather than on instances of this class.

The entry point for an application—the method that is called to begin execution—is always a static method named Main.

How to compile the geeky way (ie. if you only have the .NET Framework, without VS.NET):
I started off with some errors as usual... case sensitivity and some syntax problems…

C:\WINNT\Microsoft.NET\Framework\v1.0.3705>csc helloWorld.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

helloWorld.cs(4,30): error CS1552: Array type specifier, [], must appear before
        parameter name

C:\WINNT\Microsoft.NET\Framework\v1.0.3705>csc helloWorld.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

error CS5001: Program 'helloWorld.exe' does not have an entry point defined

C:\WINNT\Microsoft.NET\Framework\v1.0.3705>csc helloWorld.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

C:\WINNT\Microsoft.NET\Framework\v1.0.3705>helloWorld
Hello World!

Wasn’t that simple enough? So this is just the beginning. Lets see where I go from here. :-)

with 0 Comments