ASP.NET Error

We have testing our existing web application local machine and we are facing the following error
An exception of type 'System.TypeInitializationException' occurred in App_Web_rplfmtcf.dll but was not handled in user code
in our default.aspx. Some times the error occurs and sometimes it runs without any error.Any idea how to rectify this error?
karthik80cAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
Please post your stack trace and web.config file.
If this web was working before. Are any particular big changes like assembly/library/controls update?
You could compare before and current code in your source control and add changes incrementally un til it breaks.
karthik80cAuthor Commented:
Hi Miguel Oz,
Here is our stack trace take a look at this and web.config too

1.pngWeb.config
Miguel OzSoftware EngineerCommented:
Q1. Could you post the code for GetTableData method? (The actual error seems to be happening at line 502 general.cs file)
Q2. Are you using SQL server as your back end database?
Q3. What VS and  .NET version are you using?
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

karthik80cAuthor Commented:
Ans 1 : Code for  GetTableData method
 private void populateFeaturedLawyer() {

        string strSql = "SELECT * FROM wiseman_ProfRegistration WHERE featured = '1' AND active = '1' AND (status = '1' OR status = 'True') ORDER BY NEWID()";
        DataSet ds = customUtility.GetTableData(strSql);
        DataTable dt = ds.Tables[0];
        dt.Columns.Add("fullName", typeof(string));
        dt.Columns.Add("profileUrl", typeof(string));
        dt.Columns.Add("experience", typeof(string));
        dt.Columns.Add("parent_cat", typeof(string));
        dt.Columns.Add("impProfImg", typeof(string));
        dt.Columns.Add("specialism", typeof(string));

        string firstName = "";
        string lastName = "";
        foreach (DataRow row in dt.Rows)
        {
            row["profileUrl"] = customUtility.getProfileUrl(row["profileId"].ToString());
            firstName = customUtility.UppercaseFirst(row["FirstName"].ToString());
            lastName = customUtility.UppercaseFirst(row["LastName"].ToString());
            row["fullName"] = firstName + ' ' + lastName;
            row["experience"] = customUtility.getExperience(row["profileId"].ToString());
            row["parent_cat"] = customUtility.getParentCatName(row["profileId"].ToString());

            if (row["profile_pic_renamed"].ToString() == "")
            {

                row["impProfImg"] = ResolveUrl(System.Configuration.ConfigurationManager.AppSettings["lawyer_profile_image"]) + "lawyerprof.gif";
            }
            else
            {
                row["impProfImg"] = ResolveUrl(System.Configuration.ConfigurationManager.AppSettings["lawyer_profile_image"]) + row["profile_pic_renamed"].ToString();

            }

            row["specialism"] = getSpecialism(row["profileId"].ToString());

            featuredCount++;
        }
        

        MyRepeater1.DataSource = dt;
        MyRepeater1.DataBind();

       // if (featuredCount < 4) {
            //PlaceHolderSlider.Visible = false;
        //}
    }

Open in new window

Ans 2: We are using SQL as back-end Database
Ans 3: We don't  which version of visual studio the application created and .net too . but rite now we are using VS-2015 and Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.81.0
Miguel OzSoftware EngineerCommented:
Please post the correct code for GetTableData method as well as customUtility constructor.

In the mean time, my advise will be to create a new website vs2015 project and add all your files there. Upgrade projects may miss some important setups or keep old references that may interfere with your code.
If you are deploying to Windows 2012 Server or up, you should not use .NET v4.0.30319
karthik80cAuthor Commented:
Hi Miguel Oz,

Sorry for the delay here is our GetTableData method
public static DataSet GetTableData(string selectSQL)
        {
            DataSet retVal = null;
            using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["dbConnect"].ToString()))
            {
                SqlDataAdapter da = new SqlDataAdapter(selectSQL, con);
                con.Open();
                try
                {
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    retVal = ds;
                }
                catch
                {
                    HttpContext.Current.Response.Write(selectSQL);
                    HttpContext.Current.Response.End();
                }
                finally
                {
                    //  Always call Close when done reading.
                    con.Close();

                }
                return retVal;
            }
        }

Open in new window

and  customUtility constructor code is
 public static class customUtility
    {
        public static string DBPrefix = System.Web.Configuration.WebConfigurationManager.AppSettings["DBPrefix"].ToString();
        public static string ImageNotFound = System.Web.Configuration.WebConfigurationManager.AppSettings["ImageNotFound"].ToString();
        public static string WebsitePath = System.Web.Configuration.WebConfigurationManager.AppSettings["WebSitePath"].ToString() + "/";
        private static int catid = 0;
        private static int userid = 0;
        private static string profileid = string.Empty;
        private static string projectid = string.Empty; 

       
        public static int CatId
        {
            get { return catid; }
            set { catid = value; }
        }
        public static int UserID
        {
            get { return userid; }
            set { userid = value; }
        }
        public static string ProfileId
        {
            get { return profileid; }
            set { profileid = value; }
        }
        public static string ProjectId
        {
            get { return projectid; }
            set { projectid = value; }
        }


        static  customUtility() {

            SqlConnection con = ConnectDB();
            try
            {
                con.Open();
            }
            catch (Exception e)
            {
                HttpContext.Current.Response.Redirect(WebsitePath+"WebStatus.aspx?err=0");

            }
        }

Open in new window

Miguel OzSoftware EngineerCommented:
Some improvements:
1) IF customUtility is a static class there is no need for static constructor. Please remove it.
2) Do not catch errors and use Response.Redirect in your utility code, you need to catch them at page level or application level.

To narrow down the issue, In your posted GetTableData method, which line triggers the exception?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.