cawtx.2016:

When using FindAllPages () for Items or Recipes I get the error:
Precondition: value < 256
Parameter name: value
Actual value was 500.

The underlined bold code generates the exception. The exception seems to lose one page of data. For example, with recipes the Discovery() count is 9050, but after the error I only stored 8850 recipes. Any thoughts?

var service = GW2.V2.Recipes.ForDefaultCulture();
IPageContext ctx = service.FindPage(pageSize: 200, pageIndex: 0);
try
{
foreach (var page in service.FindAllPages(ctx.PageSize, ctx.PageCount))
{
try
{
foreach (var _r in page.Value) { }
}
catch (Exception ex) { Console.WriteLine(“Inner foreach: {0}”,ex.Message); }
}
}
catch (Exception ex) { Console.WriteLine(“Outer foreach: {0}”,ex.Message); }

UnknownFreak.2805:

It’s the way exceptions work, are you doing anything with the foreach (var r in page.Value)
{
you should probably use the try catch in here
}

if possible check if any of the functions have a throw exception somewhere in the documention, commenting or whatever, I assume you use the c# gw2.Net wrapper?

You should try find a more “proper” exception to catch (if there are any) like

// class def
class foo
{
private bar;
public void foobar() {
throw fooException();
}
}
class fooException : public Exception
{
exception stuff
}

// example with above class

try foo.foobar();
{
catch fooException fooEx
{
}
catch Exception ex
{
}

(I skipped some of the code formatting), and I am not sure if I used the correct class definition for inheritance (I know it is that way in c++)

also if possible post the exception message, it may help.

you could try move the try catch into the for loop (the one the error occurs in), since when it catches it will break the loop, atleast the way you have done it now.

cawtx.2016:

The exception occurs with both recipes and items. I added the try/catch after the fact to catch unhandled exceptions. The exception is System.ArgumentOutOfRange. The error message is:
Precondition: value < 256
Parameter name: value
Actual value was 500.

The statement throwing the exception is “foreach (var _r in page.Value)” which iterates through the data from “service.FindAllPages(ctx.PageSize, ctx.PageCount)” which, I believe, is from GW2NET.

UnknownFreak.2805:

I have not worked with gw2net, so I cannot really help :<
you could try if( page.Value >=256) break;
But I doubt that will work. Sorry for not able to help you, but I have not worked with GW2NET, or I tried use it, and found it highly confusing so I made my own wrapper in c++.
edit: only works if page.value is a number type (integer, float, double, etc.)

StevenL.3761:

GW2.NET dev here

I don’t remember why there is a range limit of 256, but the exception seems to indicate a bug in `FindAllPages`. I’ll look into it. For now, please use ‘FindPage’ instead.

StevenL.3761:

Can you post a full stack trace? The problem is not evident just by looking at the code.
Does the same problem occur with the FindAllPagesAsync variants?

cawtx.2016:

The exception occurs with recipes and items, but I have not seen it with prices or discovery. On the exception i lose the 200 pages. If I do one page at a time, the exception still occurs but I lose only the one item. The complete code edited in VS 2015

using System;
using GW2NET;
using GW2NET.Common;
using System.IO;

namespace TestGW2NET
{
class TestGW2NET
{
static void Main(string[] args)
{
var service = GW2.V2.Recipes.ForDefaultCulture();

foreach (var item in service.FindAllPages(200, 45))
{
try
{
foreach (var _r in item.Value)
{
Console.Write(“\r{0}”, _r.RecipeId.ToString());
}
}
catch (Exception ex)
{
using (StreamWriter outfile = new StreamWriter(@"C:\Users\Public\StackTrace.txt"))
{
outfile.WriteLine(ex.StackTrace.ToString());
}
}
}
Console.WriteLine(“\r\nDone”);
Console.ReadKey():
}
}
}

The stacktrace from the exception
at GW2NET.Items.ItemStack.set_Count(Int32 value)
at GW2NET.V2.Recipes.ConverterForItemStack.Convert(IngredientDataContract value)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at GW2NET.Common.Converters.ConverterForCollection`2.Convert(ICollection`1 value)
at GW2NET.V2.Recipes.ConverterForRecipe.Convert(RecipeDataContract value)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at GW2NET.Common.ConverterForCollectionPageResponse`2.GW2NET.Common.IConverter<GW2NET.Common.IResponse<System.Collections.Generic.ICollection<TDataContract>>,GW2NET.Common.ICollectionPage<TValue>>.Convert(IResponse`1 value)
at GW2NET.V2.Recipes.RecipeRepository.GW2NET.Common.IPaginator<GW2NET.Recipes.Recipe>.FindPage(Int32 pageIndex, Int32 pageSize)
at GW2NET.Common.Paginator.<>c__DisplayClassc`1.<FindAllPages>b__9()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at TestGW2NET.TestGW2NET.Main(String[] args) in C:\Users\Public\Documents\Visual Studio 2015\Projects\GW2API\TestGW2NET\TestGW2NET.cs:line 18

cawtx.2016:

Additional info.
I use Visual Studio 2015, the released community version, and .net 4.5.2. I run the program in debug mode and the code above was copied directly from the project.cs. With page_size set to 200 the collection count is 45. The error for recipes occurs around page numbers 40-41. With recipes I get the single exception and with items I have several.

I loaded GW2NET using the Nuget package manager in VS. The documentation states the version of the API is 1.0.1.

StevenL.3761:

You discovered a bug in the code :/

The ItemStack class was programmed to throw an exception when you try to set ItemStack.Count to a value greater than 255, which is the in-game size limit for item stacks.

What I think is happening is that certain recipes require more than 255 of an ingredient.

I don’t know why the same exception would occur for /v2/items, but basically any time you’re dealing with more than 255 of an item, it will crash.