Month: December 2017

nuget restore: Exception has been thrown by the target of an invocation

Last Updated on January 30, 2021 by sandeeppote

I am working on Sitecore 8.2 Helix based architecture. whilst doing a build received error –
MSBuild auto-detection: using msbuild version ‘14.0’ from ‘C:\Program Files (x86)\MSBuild\14.0\bin’
Error parsing solution file… Exception has been thrown by the target of an invocation.

Was able to resolve this issue suppose while merging changes the solution was missing the End Project

Project(…)
EndProject
Project(…)

Project(…)
EndProject

After adding the “EndProject”  was able to parse the solution and build.

C# 7 Local Functions

Last Updated on January 30, 2021 by sandeeppote

C# 6 Local functions are useful to create helper methods and was written as below-

 
public class LocalFunctions
{
    public int Age { get; set; }

    public string C6PrivateFunction()
    {
       return $"C#6 ==> Person is {GetEligibility(Age)}";
    }        
}

private string GetEligibility(int age)
{
   return age > 18 ? "Adult" : "Youth";
}

With C# 7.0 the same can be written as below.

Inside local functions, variables and parameters from the enclosing scope are also available and the same can also be written using as expression body.

        
public string C7LocalFunction()
{
   return $"C#7 ==> Person is {GenerateEligibility(Age)}";

   string GenerateEligibility(int age)
   {
      return age > 18 ? "Adult" : "Youth";
   }
}

public string C7LocalFunction1()
{
   return $"C#7 ==> Person is {GenerateEligibility(Age)}";

   string GenerateEligibility(int age) =>  age > 18 ? "Adult" : "Youth";
}

Enjoy coding!!!