Thursday, 28 February 2013

Unable to generate a temporary class (result=1). error CS0029: Cannot implicitly convert type 'SomeType' to 'SomeType[]'


Recently I faced a problem while accessing a webservice, I added web reference in my Visual Studio project, and created an instance of a class, and it returned me error which was something like :

Unable to generate a temporary class (result=1).
error CS0029: Cannot implicitly convert type 'SomeType' to 'SomeType[]'

-SomeType = any class name available in the Service being consumed


After some efforts and googling, I found that this is one of the known bugs of  .NET. This problem was due to a type which was structured / mapped as dynamic array, like SomeType[][]. and the consumer of such properties data type was expecting a simple SomeType Object. 

What I did, I created a local class strucutre for the WSDL file and added that file in my project. To create a code file / class for the WSDL file , you need to follow these steps:
1. Start Command Prompt of Visual Studio ( try to run as administrator)

2. Type following command :
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>wsdl /o:d:\\referencefile
.cs http://server/ServiceFile.wsdl
3. It will create the dot cs file at the location specified in the above command, copy the file and add it in your project. 
4.Remove the web reference from the project.
5.From the CS file genereated find / search for double square brackets "[][]" for SomeType / Class name for which exception is being thrown, and change it to single square pair "[]". Save and compile.

Now it must now throw exeception. Hope that helps some one. ;-)

Saturday, 23 February 2013

How to get next ID for the table - SQL Server

How to get next ID for the table - SQL Server

Usually we need to show the next ID on the new entry form, like Sale Order , Purchase Order..etc.
There are different methods for achieve this as far as I know: 

1. Create a function or stored procedure to to query the max ID for the table that we want to know the last ID generated and add 1 to the ID.
For example :
Select IsNull(Max(PurchaseOrderId),0) + 1 from PurchaseOrder

But this method will only work only when we have atleast one record in the table, other wise the Max function will return NULL, and it will be converted to zero as we have used ISNULL function and the ID which we will get will be 1, and that could only be correct if you have not inserted any record in the table, otherwise if you have entered a record in the table and deleted that record, its ID will be starting from the last ID generated.

2. Another method, that is usually used is that we check if the query / resultant of the above query is NULL, we reseed the table identity column to 1.
For example:
declare @nextId as int
set @nextId  = (Select Max(PurchaseOrderId) from PurchaseOrder)
IF @nextId IS NULL
     DBCC CHECKIDENT ('PurchaseOrder'RESEED1)
Select IsNull(@nextId,0) +1 as NextIdentity

which seems to be quite better way to achieve the next ID for a table.

But the best way I have found yet is :

3. There is a built-infunction in SQL SERVER 2005 AND LATER, and that is :

IDENT_CURRENT( 'table_name' )

Ident_Current() function gives you the last ID which was generated for the particular table.

For example :
Select IsNull(IDENT_CURRENT( 'PurchaseOrder' ) ,0) + 1 as NextIdentity

Now its upto you that how you use this function, I have created a general stored procedure, which accepts an argument for the table name, and passed that arguemnt /variable to the Ident_Current() function, and now I don't have to create seperate funtion / stored procedure for each table.

CREATE PROCEDURE [dbo].[GetCurrentIdentityForTable]
@TableName varchar(100)

SELECT IsNull(IDENT_CURRENT( @TableName ),0) + 1 as CurrentIdentity

That was all!! If you can suggest more better method to achieve this or any other alternative, please feel free to share that :-)..

Wednesday, 20 February 2013

Little Hacks for SharePoint - 2013 Part 2 ;-)

How enable Sign Inn As a Different User option

In SharePoint - 2013, Sign Inn as as different user is not available by default. To enable this option, follow these steps:
1. On your SharePoint Server, navigate to 15 hive folder.

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES

2. There will be Welcome.ascx, open this file in notepad or any of your favourite editor.
3.Search for:
4. Inside this tag, there will be multiple menu items options, include this snipped inside this tag:

<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" 
Sequence="100"  UseShortId="true" />

5. Save the file.

Now check your sharepoint site again, "Sign inn as different user" option must be available.

Hope that helps!!!

Friday, 15 February 2013

Little Hacks for SharePoint - 2013 Part 1

Enable Breadcrumb for SharePoint - 2013

Breadcrumb in SharePoint - 2013 is not visible by default. To enable breadcrumb for SharePoint - 2013, follow these steps:
1. Open your site in SharePoint Designer.
2. Open the master page being used at your site.
3. Create a copy of your master page.
4. Edit newly created master page.
5. Search for ID "GlobalBreadCrumbNavPopout"
6. In the SharePoint:PopMenu tag, either remove "Visible" attribute or change "Visible" value to true.
7. Then look for class "ms-breadcrumb-dropdownBox", there will be an attribue of display which is set to none by default. Remove this display attribute.
8. Save the master page file.
9.Right click on newly created master page which you just have modified, and click "Set as default master page", and you are done.

Open your sharepoint site, and it should not show "Navigation Up" at your site.

Saturday, 9 February 2013

Importance of Troubleshooting in Desi Style ;-)

Importance of Troubleshooting in Desi Style

I want to share my general experience to show the importance of troubleshooting.
Recently my mother bought some SAMOSA / KACHORI / MIRCHI (Snacks) at home. I first ate a chicken SAMOSA which was quite tasty :-P , then I ate kachori with some sauce / CHATNI, its tasted to me like expired, I threw that away in dust bin, again I tried daal samosa with some sauce / CHATNI, it also tasted like expired :-( and I threw that away in dust bin too. Finally the last item which was left to try was MICRCHI with sauce / CHATNI, it also tasted like expired, then instead of threwing that MIRCHI in dust bin, I ate that MIRCHI without sauce/CHATNI. and finally found that the issue was with the sauce and because of not troubleshooting this earlier :-p , I wasted 3 of food assets. 

So my friends, same is the case in the field of Information Technology, if things are not troubleshoot properly it might cause us waste of valuable time and resources.

Hope you have enjoyed my real life story to understand the importance of Troubleshooting :-D.


Tuesday, 5 February 2013

How to configure SMTP and use in SharePoint

How to configure SMTP for SharePoint

Windows version used in this Post : Windows Server 2008 R2

1. Go to Start > Administrative Tools > Internet Information Services 6

Internet Information Service (IIS) 6.0 Manager

If SMTP server feature is not installed, IIS 6.0 manager screen will look like above. As you can see there is no node under Internet Information Service. So we need to install SMTP feature from Server Manager.
3. To install SMTP feature, go to start and type "Server Manager".
in the search results it should show, Server manager. 

4. Go to "Features" from the left pane, and click "Add feature".

5. Mark "SMTP Server" , it might popup a message asking about the dependency feature to be installed before SMTP , click "Add required feature" from the poped up message. and click next. and in the next screen click Install.

Installation will be started, it will take few minutes to install SMTP:
After SMTP is installed, again open the IIS 6.0 manager. Now it should show an addiotional node with the Machine name, and a virtual SMTP server will be created after SMTP installation.

Now we need to configure SMTP server for mail account and other major configurations.
6. Right click on the Virtual server node and click properties.
7. Go to Access tab, and then click "Authentication", mark only "Anonymous" checkbox and click OK.

8. Then Click Connection in the Access tab, to configure which server or IP can use this SMTP server to send emails. 

Note: This configuration is very important in the configuration of SMTP, specially when your SMTP server machine is hosted a live IP, if any of the spammer or bot will come to know about this SMTP server open to world, it will start to use this server to send emails if it is open to be used by any server.

9. Select "Only the list below", and Add the IP address, you want to grant permissions and click OK.

10. Then Go to "Delivery" tab, and click "Outbound security". Select "Basic Authentication" and provide the user nae and password via which you can to send email, ( create a gmail account and put credentials of that account in here, you have to write user name along with domain , example ).

11. Now in the delivery tab, click "Outbound Connections...", and provide the gmail tcp port number that is "587", by default it will be 25.

12. Then in delivery tab, click "Advanced...", provide the smart host, in my case as I was using gmail account, so I provided

13. Then click OK in the properties windows for the SMTP. and note the Fully-qualified domain name value, because this value will be used in the SharePoint Configuration for SMTP.

Now we have to use this SMTP server in SharePoint. To do that, follow these steps:
1. Go Central Administration > System Settings and click "Configure outgoing email settings" under Email and Text Messages (SMS) heading.

2. Type the Fully qualitfied domain name value in the Outbound SMTP server, which you must have joted down in the prevoius step (Step 12):

3. From Address and reply to address are optional, click OK. and you are done.

Hope that helps!!