Search code examples
asp.net-corenodatime

Is NodaTime compatible with NetCoreApp 1.0?


I have dotnet core app that I'm working on that is cross-platform. I wanted to use Noda as a utility in my project but get the following error even tho I have nodatime defined as a dependency in my project:

 System.IO.FileNotFoundException: Could not load file or assembly 'NodaTimestrong text, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1'. The system cannot find the file specified.
      File name: 'NodaTime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1'
         at project.ef.CalendarHelper.ValidateTimeZone(String timezoneTypeName)
         at project.ef.CalendarHelper.

Here are the project config files:

API PROJECT

{
  "buildOptions": {
    "preserveCompilationContext": true,
    "emitEntryPoint": true,
    "warningsAsErrors": true,
    "debugType": "portable",
  "copyToOutput": {
      "include": [
        "config.json",
        "Certificate.pfx"
      ]
    }
  },
  "dependencies": {
    "AspNet.Security.OAuth.Introspection": "1.0.0-alpha2-final",
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Cors": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.EntityFrameworkCore.Design": {
        "type": "build",
        "version": "1.0.0-preview2-final"
    },
    "Microsoft.NETCore.App": "1.0.0",
    "project.ef": "1.0.0-*"
  },
  "tools": {
      "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "portable-dnxcore50+net45+win8+wp8+wpa81" ]
    }
  },
  "publishOptions": {
    "include": [
      "config.json"
    ]
  },
  "runtimes": {
      "win10-x64": {},
      "osx.10.11-x64": {},
      "ubuntu.14.04-x64": {}
  }
}

EF PROJECT

{
  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.1",
    "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.1",    
    "project.Internal.ERP": "1.1.0-*",
    "project.models": "1.0.0-*",
    "NodaTime": "2.0.0-alpha-*"
  },
  "frameworks": {
    "netstandard1.6": {
      "imports": [
        "dnxcore50",
        "portable-net451+win8"
      ]
    }
  }
}

Solution

  • Noda Time 1.x only targets PCLs. You may be able to get it to work with netcoreapp1.0, but I'm not going to guarantee it.

    But Noda Time 2.0 targets netstandard1.1, so should be fine. That's only available as an alpha release right now, but it works fine:

    project.json contents:

    {
      "buildOptions": {
        "emitEntryPoint": true
      },
      "dependencies": {
        "NodaTime": "2.0.0-alpha20160729"
      },
      "frameworks": {
        "netcoreapp1.0": {
          "dependencies": {
            "Microsoft.NETCore.App": {
              "type": "platform",
              "version": "1.0.1"
            }
          }
        }
      }
    }
    

    Program.cs contents:

    using System;
    using NodaTime;
    
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(SystemClock.Instance.GetCurrentInstant());
        }
    }
    

    That runs with no problems.