首页 新闻 会员 周边 捐助

mono和jexus环境下部署asp.net网站,用HttpWebRequest请求微信公众号接口,类型加载异常错误System.TypeLoadException: Failure has occurred while loading a type. at

0
[待解决问题]

最近项目需要在 CentOS 7.0 上部署asp.net开发的MVC微信公众号网站,已经安装好了mono和jexus环境,其他功能都正常,但是用HttpWebRequest请求微信公众号接口,类型加载异常错误:System.TypeLoadException: Failure has occurred while loading a type. at

 

System.TypeLoadException: Failure has occurred while loading a type. at WeiXinAPI.AccessToken.GetAccessToken (System.DateTime now) [0x00190] in <213a3df58a7d4d84a4f34f4158208241>:0 at newsasker.wx.Controllers.wxController.test () [0x00040] in :0

 

代码部分是这样的:

 1         //第一种请求方式
 2         public static string GetByHttpWebRequest(string url, string contentType = "application/x-www-form-urlencoded", CookieCollection cookies = null, string accept = "*/*")
 3         {
 4             string responseString;
 5             HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
 6             webRequest.Method = "GET";
 7             if (!string.IsNullOrWhiteSpace(contentType))
 8             {
 9                 webRequest.ContentType = contentType;
10             }
11             if (cookies != null)
12             {
13                 webRequest.CookieContainer = new CookieContainer();
14                 webRequest.CookieContainer.Add(cookies);
15             }
16             webRequest.Accept = accept;
17             //webRequest.AllowAutoRedirect = true;
18             //webRequest.Method = "GET";
19             //webRequest.ContentType = "application/x-www-form-urlencoded";
20             using (WebResponse response = webRequest.GetResponse() as HttpWebResponse)
21             {
22                 using (Stream stream = response.GetResponseStream())
23                 {
24                     using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
25                     {
26                         responseString = reader.ReadToEnd();
27                     }
28                 }
29             }
30             return responseString;
31         }
32 
33 
34         //第二种请求方式
35         public static string GetByWebClient(string address)
36         {
37             WebClient wc = new WebClient();
38             using (Stream st = wc.OpenRead(address))
39             {
40                 using (StreamReader sr = new StreamReader(st, Encoding.UTF8))
41                 {
42                     string res = sr.ReadToEnd();
43                     sr.Close();
44                     st.Close();
45                     return res;
46                 }
47             }
48         }
49 
50         //第三种请求方式
51         public static string GetByWebRequest(string Url, string Encode = "utf-8")
52         {
53             WebRequest request = WebRequest.Create(Url);
54             WebResponse response = request.GetResponse();
55             Stream respStream = response.GetResponseStream();
56             using (StreamReader reader = new StreamReader(respStream, Encoding.GetEncoding(Encode)))
57             {
58                 return reader.ReadToEnd();
59             }
60         }
Request GET

 

熊仔其人的主页 熊仔其人 | 菜鸟二级 | 园豆:212
提问于:2016-12-15 16:15
< >
分享
所有回答(1)
0

我个人的直觉这是一个mono的异常 你可以从张善友的博客上找到相关的做法。

 

我建议你 先运行一个 winform的程序测试下mono是否安装部署成功

尝试一下红字部分

http://www.cnblogs.com/shanyou/archive/2012/01/07/2315982.html

 

小眼睛老鼠 | 园豆:2731 (老鸟四级) | 2017-03-07 15:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册