0 votes

To give value to a List<Token> is that possible?

It throws Me this error: Use of local variable not mapped to enumerator

Code that gives error:

private void offertoro_Load(object sender, EventArgs e)
{
  List<JToken> list = JObject.Parse(System.IO.File.ReadAllText("offerids_offertoro.json")).Children().ToList<JToken>();
  List<JToken>.Enumerator enumerator1;
  try
  {
    enumerator1 = list.GetEnumerator();
    while (enumerator1.MoveNext())
    {
      JProperty source = (JProperty) enumerator1.Current;
      source.CreateReader();
      IEnumerator<JToken> enumerator2;
      if (Operators.CompareString(source.Name, "offers", false) == 0)
      {
        try
        {
          enumerator2 = source.Values().GetEnumerator();
          while (enumerator2.MoveNext())
            this.TextBox1.Text = this.TextBox1.Text + ((JObject) enumerator2.Current)["oid"].ToString() + "\r\n";
        }
        finally
        {
         // EL ENUMERATOR 2 TAMBIEN ME DA ERROR
          if (enumerator2 != null)
            enumerator2.Dispose();
        }
      }
    }
  }
  finally
  {
     // me da error AQUI <------------------------
    enumerator1.Dispose();
  }
  this.WebBrowser2.Document.Cookie = "1";
  this.c_url = "1";
  this.finallink = "1";
  this.LabelProces.Text = this.LabelProces_OpeningOT;
  this.LabelCompleted.Text = this.LabelCompletedd;
  if (MyProject.Forms.Form4.GroupBoxSpeedAverage.Checked)
    this.CompleteOffer.Interval = 7000;
  else if (MyProject.Forms.Form4.GroupBoxSpeedSlow.Checked)
    this.CompleteOffer.Interval = 9000;
  else if (MyProject.Forms.Form4.GroupBoxSpeedFast.Checked)
    this.CompleteOffer.Interval = 5000;
  this.GetAvailableOffers.Start();
}

Another error very often, it is a new virtual member in a class sealed

Código:

internal virtual Label LabelCompanyName
{
    [DebuggerNonUserCode] get
    {
        return this._LabelCompanyName;
    }
    [DebuggerNonUserCode, MethodImpl(MethodImplOptions.Synchronized)] set
    {
        this._LabelCompanyName = value;
    }
}

Is the get mainly.

One last error that I get is this: The type name 'RemoveNamespaceAttributesClosure' does not exist in the type 'InternalXmlHelper'

Code:

return (IEnumerable) obj.Cast<object>().Select<object, object>(new Func<object, object>(new InternalXmlHelper.RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject));

The List<token> you can not put null, How do I resolve it?

1voto

NaCl Points 5979

Let's start at the top...

List<JToken>.Enumerator enumerator1;

Does not have a value by default, so test with the following:

List<JToken>.Enumerator enumerator1 = null;

Given that you assign its value from a block try, the compiler understands that your variable really does not have a value and that is being used when your instance is equal to null.

So it is the same with:

IEnumerator<JToken> enumerator2;

Define without a value and you assign that value after you enter the block try, try the previous (Assign null to define it).

The block finally runs regardless of if the block try fails, try to leave a catch empty (Personally: bad practice) but do not have the variable, since at the end of the loop, the GC shall dispose of it.

Another error very often, it is a new virtual member in a class sealed: To resolve that, remove the word virtual or abstract that you have in a class sealed

In addition and to finish, I'll leave this version of your code with the modifications that I have explained above:

private void offertoro_Load(object sender, EventArgs e)
{
    List<JToken> list = JObject.Parse(System.IO.File.ReadAllText("offerids_offertoro.json")).Children().ToList<JToken>();
    List<JToken>.Enumerator enumerator1 = null;
    try
    {
        enumerator1 = list.GetEnumerator();
        while (enumerator1.MoveNext())
        {
            JProperty source = (JProperty)enumerator1.Current;
            source.CreateReader();
            IEnumerator<JToken> enumerator2 = null;
            if (Operators.CompareString(source.Name, "offers", false) == 0)
            {
                try
                {
                    enumerator2 = source.Values().GetEnumerator();
                    while (enumerator2.MoveNext())
                        this.TextBox1.Text = this.TextBox1.Text + ((JObject)enumerator2.Current)["oid"].ToString() + "\r\n";
                }
                catch {}
            }
        }
    }
    catch {}

    this.WebBrowser2.Document.Cookie = "1";
    this.c_url = "1";
    this.finallink = "1";
    this.LabelProces.Text = this.LabelProces_OpeningOT;
    this.LabelCompleted.Text = this.LabelCompletedd;
    if (MyProject.Forms.Form4.GroupBoxSpeedAverage.Checked)
        this.CompleteOffer.Interval = 7000;
    else if (MyProject.Forms.Form4.GroupBoxSpeedSlow.Checked)
        this.CompleteOffer.Interval = 9000;
    else if (MyProject.Forms.Form4.GroupBoxSpeedFast.Checked)
        this.CompleteOffer.Interval = 5000;
    this.GetAvailableOffers.Start();
}

EDIT:

Finally: The name of type RemoveNamespaceAttributesClosure does not exist in the type 'InternalXmlHelper': The detail of the error says it clearly, these calling created an instance of something that is not a member.

When you use the keyword new usually are referenced to a data type, as a string, object or InternalXmlHelper. I do not know the parameter that you are required to a new instance of the xml helper, but you need to change only this fragment of the code.

I hope it has helped you!

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X