Mono在System.Net.Http.HttpClient中无效的IL代码:.ctor(System.Net.Http.HttpClient):方法体为空

时间:2018-02-05 00:34:45

标签: c# mono dotnet-httpclient

我想让我的C#应用​​程序在Mono上运行。其目的是使用System.Net.Http.HttpClient作为REST WebApi使用。但是,当我运行它时,Mono .Net运行时抛出以下异常:

Unhandled Exception:System.InvalidProgramException: Invalid IL code in System.Net.Http.HttpClient:.ctor (): method body is empty.

以下是源代码:

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace MyProject.Data
{     
    public class DataAccess
    {
        public string Uri;
        public int DeviceId;
        static HttpClient client;
        public DataAccess(string uri)
        {
            Uri = uri;            
            client = new HttpClient();            
            client.BaseAddress = new Uri(uri);    
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }
        public async Task<List<Event>> GetEvents(int deviceId)
        {
            List<Event> events = new List<Event>();
            HttpResponseMessage response = await client.GetAsync(string.Format("devices/{0}/events", deviceId));
            if (response.IsSuccessStatusCode)
            {
                events = await response.Content.ReadAsAsync<List<Event>>();
            }
            return events;
        }

        //... other data access methods

我在Raspbian发行版上运行Mono JIT编译器版本4.6.2(Debian 4.6.2.7 + dfsg-1)。

有没有人遇到过这个?

提前致谢。 达明。

0 个答案:

没有答案