30 March 2020

How do I - Fix the "You must add a reference to assembly netstandard" error?

When using NuGet, we can easily run into assembly reference issues.  A notorious error message is:

CS0012: The type ‘System.Object’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’.

This can be very confusing especially if your app is NOT using the .NET Standard library at all.  Luckily the fix is easy enough.  Simply crack open your app.config or web.config file and added the following:

<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
</assemblies>
</compilation>
</system.web>
</configuration>
Happy coding.
C

23 March 2020

How do I - Calculate time difference between two date objects in C#?

The time difference between two date objects is easily calculated using the TimeSpan class thus:

DateTime startTime = DateTime.Now;
//Code here
TimeSpan diff = DateTime.Now - startTime;
//Use methods in [diff] to get required data.
// e.g. the below is to get time in seconds.
Console.WriteLine(diff.TotalSeconds);

Happy coding
C

SharePoint Remote Event Receivers are DEAD!!!

 Well, the time has finally come.  It was evident when Microsoft started pushing everyone to WebHooks, but this FAQ and related announcement...