C# dll in vb.net project Error "An exception of type 'System.NullReferenceException' occurred in pressapi.dll but was not handled in user code"[Answered]RSS
using System;
using System.IO;
using System.Text;
using System.Net;
namespace pressapi
{
public class Class1
{
private const string URL = "https://url";
public class myObject
{
public string id { get; set; }
public string[] batches { get; set; }
public string display_name { get; set; }
public string birth_date { get; set; }
public string email { get; set; }
public string gender { get; set; }
public string phone { get; set; }
}
public object createapi(string[] paraname1, string[] value1)
{
//dynamic xx = (HttpPost(URL, paraname1, value1));
string xx = (HttpPost(URL, paraname1, value1));
string sp = xx.Split(':')[1].Replace("}", "");
sp = sp.Replace(Environment.NewLine, "").Replace(" ", "").Replace("\"", "");
string url = "https://url";
//var json_serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
System.Web.Script.Serialization.JavaScriptSerializer json_serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
System.Web.Script.Serialization.JavaScriptSerializer s1 = new System.Web.Script.Serialization.JavaScriptSerializer();
//var s1 = new System.Web.Script.Serialization.JavaScriptSerializer();
//myObject obj = s1.Deserialize<myObject>(GetHtmlStringA(url, sp));
return s1.Deserialize<myObject>(GetHtmlStringA(url, sp));
}
protected string GetHtmlStringA(string url, string s)
{
string listFolderURI = url;//
WebRequest req = WebRequest.Create(listFolderURI);
// req.Headers.Add("Authorization", "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InN1cHBvcnRAdGVzdHByZXNzLmluIiwiZXhwIjoxNDQxMDUzODg4fQ.JgKlS7CCXdxNuMjsuyYvjCE7b4zv315iabE1xETm2n0");
req.Headers.Add("Authorization", "JWT " + s);
req.Method = "GET";
WebResponse resp = req.GetResponse();
Stream responseStream = resp.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream);
return streamReader.ReadToEnd();
}
static string HttpPost(string url, string[] paramName, string[] paramVal)
{
HttpWebRequest req = WebRequest.Create(new Uri(url))
as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
// Build a string with all the params, properly encoded.
// We assume that the arrays paramName and paramVal are
// of equal length:
StringBuilder paramz = new StringBuilder();
for (int i = 0; i < paramName.Length; i++)
{
paramz.Append(paramName[i]);
paramz.Append("=");
paramz.Append(System.Web.HttpUtility.UrlEncode(paramVal[i]));
paramz.Append("&");
}
// Encode the parameters as form data:
byte[] formData =
UTF8Encoding.UTF8.GetBytes(paramz.ToString());
req.ContentLength = formData.Length;
// Send the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
// Pick up the response:
string result = null;
try
{
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
StreamReader reader =
new StreamReader(resp.GetResponseStream());
result = reader.ReadToEnd();
}
return result;
}
catch { return null; }
}
}
}
in my vb.net project
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim x As Class1 = New Class1
Dim xz As pressapi.Class1 = New pressapi.Class1
xz.createapi({"8144529161"}, {"8144529161"})
End Sub
End Class
but i am receiving
"An exception of type 'System.NullReferenceException' occurred in pressapi.dll but was not handled in user code"
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim x As Class1 = New Class1
Dim xz As pressapi.Class1 = New pressapi.Class1
xz.createapi({"8144529161"}, {"8144529161"})
End Sub
End Class
but i am receiving
"An exception of type 'System.NullReferenceException' occurred in pressapi.dll but was not handled in user code"
Kindly help
On what line is the error?
si vis pacem para bellum
If this answered your question then please mark it as the answer.
i am using the C# code in another project and it is working fine. But when i convert the code to dll and using it in vb.net i am facing the problem
If these projects are in the same solution set a debug point and step into it so you can find what in the c# app is actually throwing the error. Your VB syntax is correct for sending parameter array's, something in the C# is not happy with the data you
are sending.
si vis pacem para bellum
If this answered your question then please mark it as the answer.
Member
16 Points
22 Posts
C# dll in vb.net project Error "An exception of type 'System.NullReferenceException' occurred in...
Oct 16, 2015 06:05 AM|Madhan seeman|LINK
Dear team,
i am using a c# dll in my vb.net project
The c# class code file
in my vb.net project
but i am receiving
"An exception of type 'System.NullReferenceException' occurred in pressapi.dll but was not handled in user code"
Kindly help
Contributor
2403 Points
828 Posts
Re: C# dll in vb.net project Error "An exception of type 'System.NullReferenceException' occurred...
Oct 16, 2015 09:45 AM|DeadTroll|LINK
On what line is the error?
If this answered your question then please mark it as the answer.
Member
16 Points
22 Posts
Re: C# dll in vb.net project Error "An exception of type 'System.NullReferenceException' occurred...
Oct 16, 2015 12:27 PM|Madhan seeman|LINK
Dear Deadtroll
i am using the C# code in another project and it is working fine. But when i convert the code to dll and using it in vb.net i am facing the problem
Contributor
2403 Points
828 Posts
Re: C# dll in vb.net project Error "An exception of type 'System.NullReferenceException' occurred...
Oct 16, 2015 01:02 PM|DeadTroll|LINK
If these projects are in the same solution set a debug point and step into it so you can find what in the c# app is actually throwing the error. Your VB syntax is correct for sending parameter array's, something in the C# is not happy with the data you are sending.
If this answered your question then please mark it as the answer.