0

I have a web API running on "netcoreapp1.0" which is using Azure Storage Client. Accessing blobs has no issue at all but when I try execute any operation with tables it throws me this error:

Exception thrown: 'Microsoft.WindowsAzure.Storage.StorageException' in System.Private.CoreLib.ni.dll

Additional information: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

The specific line it happens looks like this:

if (await table.ExistsAsync())

Even removing this, whenever it hits a line where it would actually do a HTTP call to Azure it still results the same. I am importing "net46", and I have tried also importing in my project.json "net40", but no change.

The code above is living in "Cameo.Azure.Storage.Library". It is targeting netstandard1.6 and it is referencing "WindowsAzure.Storage": "7.2.0" and "NETStandard.Library": "1.6.0".

My project.json is below:

{
  "dependencies": {
    "Cameo.Azure.Storage.Library": "1.0.0-*",
    "Cameo.GeoLocation": "1.0.0-*",
    "LightInject": "4.0.11",
    "LightInject.Microsoft.DependencyInjection": "1.0.1",
    "LocationService.Domain": "1.0.0-*",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Swashbuckle": "6.0.0-beta902"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "net46",
        "net40"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "xmlDoc": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

The librarie's project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "Cameo.Azure.Storage.Interface": "1.0.0-*",
    "LightInject": "4.0.11",
    "Microsoft.Extensions.Configuration": "1.0.0",
    "Microsoft.Extensions.Options": "1.0.0",
    "NETStandard.Library": "1.6.0",
    "WindowsAzure.Storage": "7.2.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": [
        "net46"
      ]
    }
  }
}
zoltan
  • 9
  • 5
  • Can you post your project.json ? – Ralf Bönning Sep 04 '16 at 15:02
  • I'd try removing the imports `net46` and `net40` form all of your libraries that target `netstandard1.x` or `netcoreapp1.0`, these should never be used with this monikers. Only use compatible monikers there (certain pcl libraries or ones that were packaged for `dnx4x`/`dnxcorexx` monikers. Also delete your nuget cache (C:\Users\\.nuget) and do a restore, then see if any package fails to restore. If there is any it may be the cause because it drags some unsupported assemblies into it – Tseng Sep 04 '16 at 16:54
  • If I remove or change the version of the imported frameworks then the following dependencies of WindowsAzure.Storage 7.2 complaints: Microsoft.Data.OData 5.6.4, Microsoft.Data.Edm 5.6.4, System.Spatial 5.6.4, Microsoft.Data.Services.Client 5.6.4 – zoltan Sep 04 '16 at 18:29
  • Check the dependencies section of WindowsAzure.Storage 7.2: http://www.nuget.org/packages/WindowsAzure.Storage/ – zoltan Sep 04 '16 at 18:37
  • That's your issue then, it was fetching the 4.0 dependencies because of your `net46` in imports section. You could try to add `netstandard1.3` to imports: `"imports": [ "netstandard1.3" ]` instead. Or change frameworks to `netstandard1.3` but I suspect then the app won't take it though – Tseng Sep 04 '16 at 19:47
  • Unless there is a netv4 <= $version < netv5 in the import section the project doesn't build since the dependencies of WindowsAzure.Storage targets netv4. Changing to netstandard1.3 or adding it in the imports fails even on build. Reading up the documentation (also based on the naming "imports") my understanding is that it will actually require the mentioned version of .net to run, it doesn't just circumvent nuget's version check. – zoltan Sep 05 '16 at 15:09

2 Answers2

4

You can't use .NET 4.0 or .NET 4.6 assemblies in .NET Core. You need either versions that support .NET Core (if there are any) or target .NET Core.

What you did in the following section is only to circumvent NuGet target check

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "net46",
        "net40"
      ]
    }
  },

But this will not magically make the .NET 4.x libraries work with .NET Core. .NET Core library need to target netstandard1.x or netcoreapp1.0 (there are are also some - but not all - Portable Class Libraries that were designed for Windows Phone 8, 8.1 or 10 that may work, but depends on the specific library) in order to run with .NET Core.

On top of that, you are even referencing an library for ASP.NET MVC 5 in your project, which is for sure not going to work as there is no System.Web.* anymore in .NET Core (its tightly coupled to IIS).

You will need the WindowsAzure.Storage package from Microsoft in the version 7.2, which supports .NET Core and can be found on NuGet here.

Tseng
  • 61,549
  • 15
  • 193
  • 205
  • In my custom class library I do reference "WindowsAzure.Storage": "7.2.0", but removing the imports the project doesn't even build saying that dependencies of "WindowsAzure.Storage" does not support NETStandard1.6. The MVC5 package was accidently added, and removing it didn't change anything. – zoltan Sep 04 '16 at 16:29
  • What is your custom library targeting? If your custom library only targets `net46` then it won't work either of course. Your custom library has to target `netstandard1.6` and reference the `NETStandard.Library` 1.6.0 meta package https://www.nuget.org/packages/NETStandard.Library/ (this is necessary to make netstandard1.x (where x <= 5)) work in projects that require `netstandard1.6` like netcoreapp1.0 – Tseng Sep 04 '16 at 16:33
  • Yes the library I am referring to is the one that called "Cameo.Azure.Storage.Library". It is targeting netstandard1.6 and it is referencing "NETStandard.Library": "1.6.0". – zoltan Sep 04 '16 at 16:38
  • Add your library's project.json too. Which OS are you running/developing it with? – Tseng Sep 04 '16 at 16:44
  • My dev machine is Win10. – zoltan Sep 04 '16 at 16:48
0

Changing the project.json in web API to this has solved the issue.

"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "portable-net45+win8"
      ]
    }
  }

You can only import core or portable (PCL) version of the framework. Reference:

https://blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework-monikers-tfms-are-about/

It is important to use “imports” only for versions of .NET Core and PCL (Portable Class Libraries). Using it with TFMS from the traditional .NET Framework can cause issues or malfunction.

zoltan
  • 9
  • 5