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 8143711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:11:26+00:00 2026-06-06T13:11:26+00:00

I have a bit of a unique problem. I am registering a dll as

  • 0

I have a bit of a unique problem. I am registering a dll as an assembly inside of a SQL Server database that takes in an SQLXml variable, along with two strings, and serializes the data into JSON format.

For reference, here is the method call:

[SqlProcedure]
public static void Receipt(SqlString initiatorPassword,
                           SqlString initiatorId,
                           SqlXml XMLOut,
                           out SqlString strMessge)

I would use Newtonsoft.Json or Jayrock for this application if this was any other type of app. Normally I would follow the answer given here and do something similar to:

XmlReader r = (XmlReader)XmlOut.CreateReader();
XmlDocument doc = new XmlDocument();
doc.load(r);

However, since I am using SQLClr, there are certain rules of the road. One of which is that .Load() and any other inherited method can’t be used. I think the .Net framework said it best:

System.InvalidOperationException: Cannot load dynamically generated serialization assembly. In some hosting environments
assembly load functionality is restricted,
consider using pre-generated serializer. Please see inner exception for more information. —> System.IO.FileLoadException:
LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.

I am not fluent in SqlClr by any means, but if I am understanding this blog correctly, this is caused by SqlCLR’s rules not allowing .Load() and inherited methods without being signed for and having a strong name. My DLL and the 3rd party DLLs I’m using do not have a strong name nor can I rebuild and sign them myself. So, this leaves me stuck with attempting to complete this task without using load (Unless someone knows another way this can be done)

My only solution I could come up with is a very ugly while loop that isn’t working properly, I have been getting a “Jayrock.Json.JsonException: A JSON member value inside a JSON object must be preceded by its member name” exception. Here is the while loop I wrote (not my best code, I know):

 int lastdepth = -1;
 Boolean objend = true;
 Boolean wt = false;
//Write Member/Object statements for the header omitted
JsonWriter w = new JsonTextWriter()
 while (m.Read())
                {
                    if ((lastdepth == -1) && (m.IsStartElement()))
                    {//Checking for root element
                        lastdepth = 0;
                    }
                    if ((m.IsStartElement()) && (lastdepth != -1))
                    {//Checking for Start element ( <html> )
                        w.WriteMember(m.Name);
                        if (objend)
                        { //Check if element is new Parent Node, if so, write start object
                            w.WriteStartObject();
                            objend = false;
                        }
                    }
                    if (m.NodeType == XmlNodeType.Text)
                    { //Writes text here.  NOTE: m.Depth > lastdepth here!!!!!!!
                        w.WriteString(m.Value);
                        wt = true;
                    }
                    if (m.NodeType == XmlNodeType.Whitespace) //If whitespace, keep on truckin
                    { m.Skip(); }
                    if ((m.NodeType == XmlNodeType.EndElement) && (wt == false) && (lastdepth > m.Depth))
                    {//End element that ends a series of "Child" nodes
                        w.WriteEndObject();
                        objend = true;
                    }
                    if ((m.NodeType == XmlNodeType.EndElement) && (wt == true))//Standard end of an el
                    { wt = false; }
                    lastdepth = m.Depth;
                }
                w.WriteEndObject();
                jout = w.ToString();
}

My question is, since I can’t use .load() and my while loop is a mess to debug, what would be the best approach here? The other approach commonly discussed is deserialization into an Object with matching variables but I have a rather large XML coming out of SQL Server. My loop is an attempt at dynamic programming since there are ~200 fields that are being pulled to make this XML.

Note: I am using Jayrock and working in .Net Framework 2.0. I can not change the framework version at this time.

  • 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-06-06T13:11:27+00:00Added an answer on June 6, 2026 at 1:11 pm

    Code For JayRock

    Your code is throwing an exception:

    A JSON member value inside a JSON object must be preceded by its member name.
    

    This exception comes from the method:

        private void EnsureMemberOnObjectBracket() 
        {
            if (_state.Bracket == JsonWriterBracket.Object)
                throw new JsonException("A JSON member value inside a JSON 
                 object must be preceded by its member name.");
        }
    

    The containing call from that code is from:

        public sealed override void WriteString(string value)
        {
            if (Depth == 0)
            {
                WriteStartArray(); WriteString(value); WriteEndArray();
            }
            else
            {
                EnsureMemberOnObjectBracket();
                WriteStringImpl(value);
                OnValueWritten();
            }
        }
    

    The only time that your code calls a method which calls EnsureMemberOnObjectBracket is from one place:

    if (m.NodeType == XmlNodeType.Text)
    { //Writes text here.  NOTE: m.Depth > lastdepth here!!!!!!!
     w.WriteString(m.Value);
     wt = true;
    }
    

    This means that there is an error here. Perhaps you could do some try/catch, or refinement of your code here.

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

Sidebar

Related Questions

I have a bit of a unique problem with an upcoming project; I need
I have a bit of a unique challenge today. I have a client that
I have a bit of a problem that I can't seem to code my
I have a bit of a strange problem. I have a music app that
Hey guys, I have a bit of a problem that I can't solve. I'm
I have a bit of a unique database structure but the query I'm attempting
I'm experiencing something a bit strange. I have a table on SQL Server 2008,
So I have a very unique problem. I am using php-ODBC (32 Bit) to
I'm a bit new with Mysql and have a problem with unique constraints :p
I have a bit of an SQL problem. Here are my tables: areas(id, name,

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.