Can't Load Queue<string>

Discussion and help for Easy Save 3
Post Reply
Nixtheworld
Posts: 5
Joined: Sat Feb 04, 2023 9:40 pm

Can't Load Queue<string>

Post by Nixtheworld »

Error on compile to IOS: MissingMethodException: Constructor on type 'System.Collections.Generic.Queue`1[[System.String,

Code: Select all

  
var queue = new Queue<string>();
queue.Enqueue("Test");
ES3.Save("queue", queue, "queue.es3");
var loaded = ES3.Load<Queue<string>>("queue", "queue.es3");
Debug.Log(loaded.Count);
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can't Load Queue<string>

Post by Joel »

Hi there,

Please could you post the complete error with stack trace? It looks like the stripping settings in your project are stripping the required constructor of Queue, but it's not possible to tell without the complete message.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Nixtheworld
Posts: 5
Joined: Sat Feb 04, 2023 9:40 pm

Re: Can't Load Queue<string>

Post by Nixtheworld »

Hey Joel, I am on your Discord. Would it be easier to post there?
Nixtheworld
Posts: 5
Joined: Sat Feb 04, 2023 9:40 pm

Re: Can't Load Queue<string>

Post by Nixtheworld »

Code: Select all

MissingMethodException: Constructor on type 'System.Collections.Generic.Queue`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' not found.
  at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x00000] in <00000000000000000000000000000000>:0 
  at ES3Types.ES3QueueType.Read (ES3Reader reader) [0x00000] in <00000000000000000000000000000000>:0 
  at ES3Reader.Read[T] (ES3Types.ES3Type type) [0x00000] in <00000000000000000000000000000000>:0 
  at ES3Reader.Read[T] (System.String key) [0x00000] in <00000000000000000000000000000000>:0 
  at ES3.Load[T] (System.String key, ES3Settings settings) [0x00000] in <00000000000000000000000000000000>:0 
  at PreloadMenu.Awake () [0x00000] in <00000000000000000000000000000000>:0 
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can't Load Queue<string>

Post by Joel »

Nixtheworld wrote: Fri Feb 17, 2023 9:08 am Hey Joel, I am on your Discord. Would it be easier to post there?
Here would be better just so that if someone else runs into the same issue it'll be easier for them to find the solution as this forum is indexed by Google.
MissingMethodException: Constructor on type 'System.Collections.Generic.Queue`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' not found.
at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0
at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x00000] in <00000000000000000000000000000000>:0
at ES3Types.ES3QueueType.Read (ES3Reader reader) [0x00000] in <00000000000000000000000000000000>:0
at ES3Reader.Read[T] (ES3Types.ES3Type type) [0x00000] in <00000000000000000000000000000000>:0
at ES3Reader.Read[T] (System.String key) [0x00000] in <00000000000000000000000000000000>:0
at ES3.Load[T] (System.String key, ES3Settings settings) [0x00000] in <00000000000000000000000000000000>:0
at PreloadMenu.Awake () [0x00000] in <00000000000000000000000000000000>:0
This definitely looks like your stripping settings mean that the constructor is being stripped out. There's a number of ways to prevent this from happening:

The easiest method should be to simply put the following at the top of your method:

Code: Select all

var tempQueue = new Queue<string>(new List<string>());
This just tells the compiler that this constructor is being used so don't strip it. We don't actually do anything with this Queue.

Another way is by creating a link.xml file on your Assets folder. The following should do the job:

Code: Select all

<linker>
    <assembly fullname="mscorlib">
        <type fullname="System.Collections.Generic.Queue`1" preserve="all"/>
    </assembly>
</linker>
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Nixtheworld
Posts: 5
Joined: Sat Feb 04, 2023 9:40 pm

Re: Can't Load Queue<string>

Post by Nixtheworld »

Adding - var tempQueue = new Queue<string>(new List<string>()); worked. Does this have to be in every scene or does it just have to run on the first scene?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can't Load Queue<string>

Post by Joel »

It doesn't matter when it runs, just as long as it's in a method which is called at some point in your project (otherwise the method will be stripped).

You might instead be able to create a field in one of your scripts with that initialiser. I.e:

Code: Select all

Queue<string> tempQueue = new Queue<string>(new List<string>());
However, it's less clear whether fields will be stripped or not so you might find it easier to keep it in a method as described in my previous post.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply