Wednesday, February 8, 2017

Fix Visual Studio 2013 Error “No exports were found that match the constraint”

When loading an existing universal Windows App solution, I noticed that the shred project failed to load in Visual Studio 2013. When creating a new one, I ran into an error as shown below.

No exports were found that match the constraint: ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService RequiredTypeIdentity Microsoft.VisualStudio.Text.ITextDocumentFactoryService

I solved this problem by clearing Visual Studio Component Model Cache.

Just delete or rename this folder: %AppData%\..\Local\Microsoft\VisualStudio\12.0\ComponentModelCache

Thursday, December 10, 2015

SQL query to LinQ sub query simple tricks


I have the following SQL query and I will change it in LINQ, Simple query but have to do in one query to reduce database call. Here is the SQL query
select * from td_Accountline 
where 
    BonusPlanID = 1
    and Amount > 0
    and Ord_Sub_ID like '%SMPORD%' 
    and MONTH(Created) = 11
    and YEAR(Created) = 2013  
    and Ord_Sub_ID not in (
        select Ord_Sub_ID 
        from td_Accountline 
        where 
            BonusPlanID =3 and
            Ord_Sub_ID like '%SMPORD%'
    ) 

My LinQ query is bellow, I have used 'let'. The 'Let' keyword allows storing the results of a query which can be used in a subsequent query.
  var accountdata = from acc in currentDatabase.td_Accountline 
                    where
                    acc.BonusPlan.BonusPlanID == 1
                    && acc.Amount > 0
                    && acc.Ord_Sub_ID.Contains("SMPORD")
                    && acc.Created.Value.Month == 11
                    && acc.Created.Value.Year == 2015
                    let accNot = from accN in currentDatabase.td_Accountline 
                                 where
                                 accN.BonusPlan.BonusPlanID == 3
                                 && accN.Ord_Sub_ID.Contains("SMPORD")
                                 select accN.Ord_Sub_ID
                             where !accNot.Contains(acc.Ord_Sub_ID)
                    select acc;


Happy LinQ Sub Query :)

Thursday, March 12, 2015

Asp .net MVC hidden field can't set value using jquery [Solved]

My hidden field is declared like this:
@Html.HiddenFor(model => model.Token, new { ClientIDMode = "Static" })

Then assign the value bellow way in hidden field
 var token = response.id;                    
 $('#Token').val(token);

Mention: You have to Set ClientIDMode="Static" and then you can use $('#Token').val(token); to set the value in asp.net hidden

Happy programming !

Wednesday, March 4, 2015

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0 [Solved]

When I am working on mvc application using vs2013 and windows 8.
I got this bellow error messsage :

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

[Solved]

I fixed this issue bellow way:
Project-->Manage Nuget Package-->Updates --> nuget.org-->Update All

Monday, February 16, 2015

How to find the Second value (could be largest or lowest) from a table.?


I have One table with StatusIDHeld in "UserStatusHistory"Table with this column userid,StatusIDHeld and statusChangedOn. One customer could be multiple StatusIDHeld . I am finding out just previous one StatusIDHeld that mean the second StatusIDHeld which just before he had hold.

To be able to get 1., 2. or n-th record depending on sort order, use ROW_NUMBER() function.
                        SELECT StatusIDHeld 
   FROM
   (
    SELECT StatusIDHeld, ROW_NUMBER () OVER(order by statusChangedOn DESC) as RowNo
    FROM UserStatusHistory where userid= 1037146 
   ) AS t
   where t.RowNo = 2


Happy Query .....

SQL SERVER – Simple Example of Cursor with update table

A cursor is a set of rows together with a pointer that identifies a current row.

DECLARE cursor_activatedOnEmpty CURSOR FOR SELECT userid, statusid,RegisteredOn, activatedOn, RealActivationDate FROM UserProfile where statusID=1330 and  activatedOn is null; 
DECLARE @userid INT;
DECLARE @statusid INT;
DECLARE @RegisteredOn Date;
DECLARE @activatedOn Date;
DECLARE @RealActivationDate Date;
DECLARE @PreviousStatusID INT;
OPEN cursor_activatedOnEmpty;
FETCH NEXT FROM cursor_activatedOnEmpty INTO @userid, @statusid,@RegisteredOn, @activatedOn,@RealActivationDate;
WHILE @@FETCH_STATUS = 0  
BEGIN    
 
 SET @PreviousStatusID = (select top 2 StatusIDHeld from dbo.UserStatusHistory where userid=@userid order by statusChangedOn DESC)  
       if (@PreviousStatusID=1325)
       update UserProfile set activatedOn=@RegisteredOn where userid=@userid

       FETCH NEXT FROM cursor_activatedOnEmpty INTO @userid, @statusid,@RegisteredOn, @activatedOn,@RealActivationDate;
END;
CLOSE cursor_activatedOnEmpty;
DEALLOCATE cursor_activatedOnEmpty;

Happy Cursor!!

Sunday, February 8, 2015

Complex Json deserialization C# (class is not supported for deserialization of an array)


I am trying to deserialization array bellow this way.
This is my json file.
[
   [
      {
         "name":"Riaz Kabir",
         "url":"https://recruit.theladders.com/resumeviewer?jobseekerId=01-sid-BDLBKUPMIL6HGZ22MOAJJIWYGE",
         "summary":"ASP.NET MVC Developer Hewlett-Packard (HP) (1/2013-Present) Location: Schenectady, NY Compensation: $50k+ Previous Titles/Companies: 2016 ►",
         "role":"ASP.NET MVC Developer at Hewlett-Packard (HP)",
         "compensation":"$50k+",
         "education":"BS, Computer Science and Engineering, Asian University of Bangladesh",
         "expertise":"Databases , IT Consulting , Software Development , Front End Development",
         "years":"Less than 5",
         "relocation":"Schenectady, NY Within 1000 miles of 12305 Would need to relocate here",
         "resume":"0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAP",
         "resumeExtension":"doc",
         "resumeMimeType":"application/msword"
      }
   ]
]

Bellow my candidate Resume class
public class CandidateResume
        {

            public string name { get; set; }
            public string url { get; set; }
            public string summary { get; set; }
            public string role { get; set; }
            public string compensation { get; set; }
            public string education { get; set; }
            public string expertise { get; set; }
            public string years { get; set; }
            public string relocation { get; set; }
            public string resume { get; set; }
            public string resumeExtension { get; set; }
            public string resumeMimeType { get; set; }

        }

I have bind this "WebScrappingCandidate" class this bellow way.
                JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 };
                List> myobj = jsSerializer.Deserialize>>(description);

                foreach (List listCandidateResume in myobj)
                {
                    foreach (CandidateResume candidateResume in listCandidateResume)
                    {
                        WebScrappingCandidate webScrappingCandidate = new WebScrappingCandidate();
                        webScrappingCandidate.FullName = candidateResume.name;
                        webScrappingCandidate.ResumeUrl = candidateResume.url;
                        webScrappingCandidate.Summary = candidateResume.summary;
                        webScrappingCandidate.PositionName = candidateResume.role;
                        webScrappingCandidate.Compensation = candidateResume.compensation;
                        webScrappingCandidate.Education = candidateResume.education;
                        webScrappingCandidate.Skills = candidateResume.expertise;
                        webScrappingCandidate.YearsOfExperience = candidateResume.years;
                        webScrappingCandidate.Relocation = candidateResume.relocation;                        
                        webScrappingCandidate.ResumeText = candidateResume.resume;                                                                  
                    }                                       
                }   

Happy Programming :)

Monday, March 24, 2014

Files has invalid value "<<<<<<< .mine". Illegal characters in path [Solved]

First you have to remove any characters like "<<<<<<< .mine" or similar from the file that you will see in your project Folder.

If you don't find "<<<<<<< .mine" this one then you have to search in bollow this file
.csproj.FileListAbsolute.txt

which contains a list of all the paths and recompile ...it worked for me :)

Wednesday, December 11, 2013

Keep password textbox value during postback asp.net


In this article, I will explain how to keep password & Retype password textbox value during postback in asp.net
 protected void Page_Load(object sender, EventArgs e)
    {
       if (!(String.IsNullOrEmpty(txtPassword.Text.Trim())))
        {
            txtPassword.Attributes["value"] = txtPassword.Text;
        }
        if (!(String.IsNullOrEmpty(txtRePassword.Text.Trim())))
        {
            txtRePassword.Attributes["value"] = txtRePassword.Text;
        }
   }



Hope freshers will find it helpful :)

Thursday, November 14, 2013

C# multiple value return from single function

There are a number of ways to return two object from one function. You can class or structure and another one as out parameter. Alternatively, you can use generic type with two members. Such type, in particular, it Tuple:

#I am using Tuple to returns 2 datetime value(fromDate , toDate )
  public Tuple GetDates()
   {

          DateTime fromDate = DateTime.Now;
          DateTime toDate = DateTime.Now;
          int year = Convert.ToInt32(this.ddlQYear.SelectedItem.Value);

            if (Convert.ToInt32(ddlQ.SelectedItem.Value) > 0)
            {
                int month = Convert.ToInt32(ddlQ.SelectedItem.Value);
                fromDate = new DateTime(year, month, 1);
                if (month == 12)
                    toDate = new DateTime(year + 1, 1, 1);
                else
                    toDate = new DateTime(year, month + 1, 1);
            }
            return new Tuple(fromDate, toDate);
   }
===========Call this function bellow way==============================
            
DateTime fromDate = GetDates().Item1;
DateTime toDate = GetDates().Item2;


#Another way use "out" keyword:

 public static int GetDates(out DateTime FDate, out DateTime TDate)
   {
            DateTime fromDate = DateTime.Now;
            DateTime toDate = DateTime.Now;

           // Calculate your date

            FDate=fromDate ;
            TDate=toDate
     

         return 1;
   }
Hope that this helps!!