Tuesday, June 14, 2016

How to send a mail using C#

 private void send-mail( )

            {
            string senderID = "sender@gmail.com";// use sender’s email id here..
             const string senderPassword ="password of sender"; // sender password here…
           
                  Console.WriteLine("sending mails......");
                  SmtpClient smtp = new SmtpClient
                  {
                   Host = "smtp.gmail.com", // smtp server address here…
                   Port = 587,
                  EnableSsl = true,
                  DeliveryMethod = SmtpDeliveryMethod.Network,
                   Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
                  Timeout = 30000,
                  };


                 MailMessage message = new MailMessage(senderID, "receiver@gmail.com");
                 message.subject= "hi ";
                  message.Body="   ur body  ";
                 smtp.Send(message);
                Console.WriteLine("mail sended successfully");
               }

Monday, June 6, 2016

Error : Maximum request length exceeded

in web.config file
Sol: 
<compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647"/>
  
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880"/>
    </authentication>
   
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483647"/>
      </requestFiltering>
    </security>

   </system.webServer>

object reference not set to an instance of an object. meaning

Object reference not set to an instance of an object.

Null Reference Exception:

    In simple words this error means that you are trying to use a reference of an object which is "null".
Means, you haven't initialize  it. If you have to use any object you have to initialize it.

                              This is a RUN TIME exception.

Thursday, June 2, 2016

The best overloaded method match for 'System.Math.Round(double, int)' has some invalid arguments cannot convert from 'float?' to 'double'

sol: double xx= (double)xx[0].xxxxx;

ERROR : The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[class]', but this dictionary requires a model item of type 'class'.

SOLUTION :

    public CLASSNAME gEtsinglerecord(int Id)
        {
            CLASSNAME retval = null;
            retval = Entity.CLASSNAME.Where(s => s.Id == Id).FirstOrDefault();
            return retval;
        }


We have to use "First or Default( )" to the get record based on SINGLE ID value. 

Tuesday, May 31, 2016

Error occurred during a cryptographic operation. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.

Server Error in '/' Application.

Error occurred during a cryptographic operation.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.

Source Error:


Line 53:                     //var prin = new GenericPrincipal(id, userRoles);
Line 54:                     //HttpContext.Current.User = prin;
Line 55:                     var ticket = FormsAuthentication.Decrypt(encTicket);
Line 56:                     var id = new UserIdentity(ticket);
Line 57:                     string[] userRoles = { "A" };


Source File: c:\Naresh\                                        Global.asax.cs    Line: 55

Stack Trace:


[CryptographicException: Error occurred during a cryptographic operation.]
   System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.Homogen
izeErrors(Func`2 func, Byte[] input) +115
   System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.Unprot
ect(Byte[] protectedData) +70
   System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
 +9692626
   CanPayApp.MvcApplication.MvcApplication_PostAuthenticateRequest(Object
 sender, EventArgs e) in c:\Naresh\05 31 2016\CanPayApp\CanPayApp\Global
.asax.cs:55
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecut
ionStep.Execute() +141
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
 completedSynchronously) +69



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

=============================================================================
=Cleanup code and open... 

For anyone who hasn't solved their problem, I was missing the "machineKey" entry for encrypt/decrypt in my web.config

=
Try clearing your cache and cookies in order to mitigate the error. I suspect some sort of error occurred when information was sent to or from the server.

Friday, May 13, 2016

The localhost page isn’t working in visual studio

Resolved::: solution> project properties> change iis express port number ----

Wednesday, March 9, 2016

Convert Datatable to List

private static List<T> ConvertDataTable<T>(DataTable dt)  
{  
    List<T> data = new List<T>();  
    foreach (DataRow row in dt.Rows)  
    {  
        T item = GetItem<T>(row);  
        data.Add(item);  
    }  
    return data;  
}  
private static T GetItem<T>(DataRow dr)  
{  
    Type temp = typeof(T);  
    T obj = Activator.CreateInstance<T>();  
  
    foreach (DataColumn column in dr.Table.Columns)  
    {  
        foreach (PropertyInfo pro in temp.GetProperties())  
        {  
            if (pro.Name == column.ColumnName)  
                pro.SetValue(obj, dr[column.ColumnName], null);  
            else  
                continue;  
        }  
    }  
    return obj;  

Tuesday, March 8, 2016

Visual Studio Expand/Collapse keyboard shortcuts


Collapse to Definitions: CTRL + M + O

Expand all Outlining: CTRL + M + X

Thursday, March 3, 2016

Not Running in Release Mode in Visual Studio

  • Right click Project
  • Properties
  • Build
  • Advanced
  • Set Debug Info to full or pdb only