Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:47:52+00:00 2026-05-26T22:47:52+00:00

I’m getting an error when trying to deserialize some data into a class. The

  • 0

I’m getting an error when trying to deserialize some data into a class. The error is: “System.RuntimeType is inaccessible due to its protection level. Only public types can be processed.”

The error and all the other searches I’ve done say that something isn’t public. I’ve made everything public (but I don’t want to have to do that if I can avoid it), but still can’t figure it out.

Here is my original code:

private void RequestTest()
{
    SMDataRequest dataRequest = new SMDataRequest();

    SMListInvoicesRequest invoiceRequest = new SMListInvoicesRequest();

    SMListInvoicesResponse response = (SMListInvoicesResponse)dataRequest.GetData(invoiceRequest);
}


public class SMDataRequest
{
    private const string URI = UriHere;

    public SMResponse GetData(SMRequest request)
    {
        //SMResponse response;

        WebRequest webRequest = WebRequest.Create(URI);

        webRequest.Method = "POST";
        webRequest.ContentType = "text/XML";

        string parameters = string.Format(request.GetRequest(), USERNAME, PASSWORD);

        webRequest.ContentLength = parameters.Length;

        // Write the request
        StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream(), Encoding.ASCII);

        requestWriter.Write(parameters);
        requestWriter.Close();

        // Do the request to get the response
        StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());

        string response = responseReader.ReadToEnd();

        XmlDocument doc = new XmlDocument();

        doc.LoadXml(response);

        XmlNode node = doc.SelectSingleNode("response");

        return request.GetResponse(node.FirstChild.InnerXml);
    }
}


public abstract class SMRequest
{
    public abstract string Action { get; }
    public abstract string Data { get; }
    public abstract string Row { get; }

    internal const string XML_ACTION = "<root><action>{0}</action>{1}</root>";
    internal const string XML_DATA = "<data>{0}{1}</data>";
    internal const string XML_ROW = "<row>{0}{1}</row>";

    internal const string XML_AUTH = "<auth_username>{0}</auth_username><auth_password>{1}</auth_password>";

    private readonly string _userName;
    private readonly string _password;

    protected SMRequest()
    {
       //Set username and password
    }

    public string GetRequest()
    {
        return string.Format(XML_ACTION, Action, GetDataInfo());
    }

    public virtual string GetDataInfo()
    {
        return string.Format(XML_DATA, GetAuthInfo(), Data);
    }

    protected internal abstract SMResponse GetResponse(string responseData);

    internal string GetAuthInfo()
    {
        return string.Format(XML_AUTH, _userName, _password);
    }

    internal object DeserializeObject(string xml, object data)
    {
        object result = null;

        xml = xml.Replace("utf-16", "utf-8");

        try
        {
            XmlSerializer serializer = new XmlSerializer(data.GetType());
            MemoryStream stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(xml));
            result = serializer.Deserialize(stream);
        }
        catch (Exception)
        {
        }

        return result;
    }
}


[Serializable]
public class SMListInvoicesRequest : SMRequest
{
    public override string Action
    {
        get { return "list-invoices"; }
    }

    public override string Data
    {
        get { return string.Empty; }
    }

    public override string Row
    {
        get { throw new NotImplementedException(); }
    }

    protected internal override SMResponse GetResponse(string responseData)
    {
        SMListInvoicesResponse invoiceReponse = new SMListInvoicesResponse();

        invoiceReponse = (SMListInvoicesResponse)DeserializeObject(responseData, invoiceReponse.GetType());

        return invoiceReponse;
    }
}

Thank you in advance for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:47:53+00:00Added an answer on May 26, 2026 at 10:47 pm

    You are trying to deserialize a Type:

        invoiceReponse = (SMListInvoicesResponse)DeserializeObject(responseData, invoiceReponse.GetType());
    

    The second parameter, invoiceReponse.GetType(), is passed to the data parameter and the data parameter is used as follows:

    XmlSerializer serializer = new XmlSerializer(data.GetType());
    

    I think you should change your call to just send invoiceResponse.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.