0
votes

I'm a C# newbie, so bear with me. I'm running the latest dotnet Docker container with the dotnet command line tools, and am attempting to also use RestSharp to do REST requests to a remote API. I managed to get RestSharp added to my project.json, and a 'dotnet restore' completed with no error messages, but when I try to actually use RestSharp in a controller, I get this error:

/path/to/MyController.cs(18,30): error CS0012: The type 'Uri' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Compilation failed.

I know that this is happening as a result of RestSharp because when I comment out all the RestSharp code the error message goes away.

I'm thinking it probably has something to do with my project.json file, which I'll paste at the end of this message. For those of us using Linux, we don't have access to NuGet, and we have to create our project.json files by hand. This one was originally created by a yeoman scaffolder for dotnet.

Thanks for your help!


    {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.1.0",
          "type": "platform"
        },
        "Microsoft.AspNetCore.Mvc": "1.0.1",
        "Microsoft.AspNetCore.Routing": "1.0.1",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Configuration.CommandLine": "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",
      },

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

      "frameworks": {
        "netcoreapp1.0": {
          "dependencies": {
            "RestSharp": "105.2.3",
            "System.Net.Http": "4.3.0",
            "System.Runtime": "4.3.0"
          },
          "frameworkAssemblies": {
          },
          "imports": [
            "net452",
            "dotnet5.6",
            "portable-net45+win8"
          ],
        }
      },

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

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

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

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

      "tooling": {
        "defaultNamespace": "WebAPIApplication"
      }
1
Ok ... any ideas how I can reconfigure my project.json to alleviate this problem? I'm not married to netcoreapp1.0 at all as I'm just beginning with coding this app. The only thing I really need right now is RestSharp.ArkieCoder
RestSharp v106 support .NET Standard 2.0 so if your code worked with RestSharp 105 under .NET Framework - it will also work with .NET Core 2. RestSharp.NetCore package is not from RestSharp team and is not supported by us. It is also not being updated and the owner does not respond on messages, neither the source code of the package is published.Alexey Zimarev

1 Answers

0
votes

This project.json worked and I was able to use RestSharp with netcoreapp1.1 --

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "RestSharp.NetCore": "105.2.4-rc4-24214-01"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
    "Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final"
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

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

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

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

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

  "tooling": {
    "defaultNamespace": "WebAPIApplication"
  }
}