0

I am trying to get the current Hijri date in my Xamarin app.

I tried:

Calendar hijri = new HijriCalendar();

and

Calendar hijri = new HijriCalendar();

but getting:

Error CS0246: The type or namespace name 'HijriCalendar' could not be found (are you missing a using directive or an assembly reference?) (CS0246)

although I already added the:

using System.Globalization
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

HijriCalendar is available in .NET Standard and not in old good PCL.

So update your project to latest and greatest .NET Standard 2.0:

  1. Unload your PCL project (right click -> unload), and start editing it (right -> click edit)
  2. Delete Everything in the csproj and insert this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <!--<PackageReference Include="" Version=""/>-->
  </ItemGroup>

</Project>
  1. Add back NuGets (simply open packages.config, and add the package references above, or via the NuGet package manager.

  2. Delete AssemblyInfo.cs (this is now in the csproj) and packages.config (also in csproj via PackageReference)

Original gist.

If you are working with Visual Studio for Mac you can use an extension to convert the project type automatically.

P.S.: Alternatively as suggested by SushiHangover you can add a NuGet package. However, I would recommend to switch to .NET Standard asap.
P.S.S: More about .NET Standard here.

EvZ
  • 11,889
  • 4
  • 38
  • 76
  • I am using Visual Studio for Mac but I didn't understand point 3 and 4 please.. which package I should add? – Jassim Al Rahma May 05 '18 at 15:40
  • If you are on Mac use Mutatio => https://github.com/yuv4ik/Mutatio it is extension that will automatically convert the project for you. Check the Installation section in the link I shared. – EvZ May 05 '18 at 15:41
  • If you still want to convert the project manually check the next video: https://www.youtube.com/watch?v=F0VWCmj2adw – EvZ May 05 '18 at 15:48
  • Don't see a point in doing it manually since there is a way to automate the process. BTW I am the author of this extension. – EvZ May 05 '18 at 15:58
  • I started doing it manualy :) I have a question here please.. Do I also need to add packages such as Microsoft.NETCore.Platforms, Microsoft.NETCore.Targets, NETStandard.Library, System.IO, System.Runtime, etc – Jassim Al Rahma May 05 '18 at 16:11
  • You should have a packages.json or project.json where all the NuGet packages should be listed. Most probably you will not need all of them in the new type of project. So start with all the external packages non ms ecosystem related and see ... – EvZ May 05 '18 at 16:15
  • Then please accept and upvote the answer as described here: https://stackoverflow.com/help/someone-answers – EvZ May 05 '18 at 16:40
  • I have one last question please.. I have done this for the PCL project but do I need to do it for the other two projects in my solution, iOS and Droid? – Jassim Al Rahma May 05 '18 at 17:48
  • No, you cant. For more details check the links to official documentation in my answer. – EvZ May 05 '18 at 18:25