3

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"
      ]
    }
  }
}
chris
  • 1,152
  • 1
  • 15
  • 37
  • What does your dependency look like? 2.0.0-alpha20160729 should be fine with netcoreapp1.0, without any imports. – Jon Skeet Oct 31 '16 at 18:07
  • It seems to be: https://www.nuget.org/packages/NodaTime/2.0.0-alpha20160729 - targets netstandard1.1 so you should be fine. Can you show your project.json? I looked into package contents and it does not contain NodaTimestrong assembly only NodaTime. – Pawel Oct 31 '16 at 18:07
  • i revised my question to include more details. I have two project.json's - one for the api and another for my database logic. Is there a sample dotnet core project posted somewhere that I can cross reference? @JonSkeet I see in your sample below that your referencing 1.0.1 and im referencing 1.0.0, maybe there's something there. I'm using NodaTime to replicate the solution to this question http://stackoverflow.com/questions/17348807/how-to-translate-between-windows-and-iana-time-zones – chris Oct 31 '16 at 19:47
  • 1
    @chris: I don't know whether the 1.0.0 vs 1.0.1 difference is important, but I'd specify the *exact* version of Noda Time rather than using a *, and I'd at least try adding the dependency in both project.json files, just as a starting point. (You can then take out the dependency from the API project when you've ruled out that aspect as the cause of the problem.) – Jon Skeet Oct 31 '16 at 19:48

1 Answers1

5

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • turns out explicitly defining the version number for the nodatime dependency resolved my problem. sometimes its the simplest solution haha - thanks! – chris Oct 31 '16 at 20:04
  • @chris: You might want to look at which version it was previously picking up - if you look at `project.lock.json` you can see the exact resolved dependencies. – Jon Skeet Oct 31 '16 at 20:10
  • oh wow - I looked in my nuget cache and it was previously using NodaTime.2.0.0-alpha20140807.nupkg . That might explain it haha – chris Oct 31 '16 at 20:48