Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Windows Build Fail(solved)

Discussion in 'Windows' started by patrickcummins, Oct 3, 2014.

  1. patrickcummins

    patrickcummins

    Joined:
    Jul 12, 2013
    Posts:
    11
    Hi all,

    This is my first time building for windows and I get an error which wont allow me to complete my build. I have searched the internet for a solution to this problem but nothing so far.

    The error is:
    Error building Player: Exception: Error: method `System.Collections.Generic.List`1<!!0> System.Collections.Generic.List`1<GAFSequenceData>::ConvertAll<System.String>(System.Converter`2<!0,!!0>)` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Collections.Generic.List`1<System.String> GAFAnimationAsset::getSequenceIDs(System.Int32).
    Error: method `System.String System.Text.Encoding::GetString(System.Byte[])` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.String GAFReader::ReadString(System.IO.BinaryReader).

    Is there anyone out there that would know how to fix this error?

    Thanks in advance.
     
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Originally Encoding.GetString is a virtual method. I believe in WinRT you have to use the override for it in a derived class. You'll have to find the code in your script that calls that. Do you know if you're using Unicode (UTF16) or UTF8?

    Let's say for example that your byte array is called "myBytes". Here is how you'd need to change the implementation:

    Code (csharp):
    1.  
    2. var myString = System.Text.Encoding.UTF8.GetString(myBytes, 0, myBytes.Length);
    3.  
    The above says:

    1. We're using UTF8 encoding
    2. We're starting at position "0" in the array of bytes
    3. We're reading all of the bytes in the array (myBytes.Length)

    If you're using UTF16, then just change the encoding call above accordingly.
     
  3. patrickcummins

    patrickcummins

    Joined:
    Jul 12, 2013
    Posts:
    11
    I'm sorry if I sound really stupid, but do I have to look through all my scripts to find which one calls System.Text.encoding?
     
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    No... look at the error message. It tells you where it exists. GAFReader.ReadString. So you just need to find that class and method.
     
  5. patrickcummins

    patrickcummins

    Joined:
    Jul 12, 2013
    Posts:
    11
    Ah thanks so much, I'm so stupid that I didnt see that.

    my method looks like this

    Code (CSharp):
    1. public static string ReadString(BinaryReader _Reader)
    2.     {
    3.         ushort len = _Reader.ReadUInt16();
    4.  
    5.         byte [] data = _Reader.ReadBytes(len);
    6.  
    7.         System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
    8.         return enc.GetString(data);
    9.     }
    Am I replacing the System.Text line already their with the line you posted above?
     
  6. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Yeah so:

    Code (csharp):
    1.  
    2. return System.Text.Encoding.UTF8.GetString(data, 0, data.Length);
    3.  
     
  7. patrickcummins

    patrickcummins

    Joined:
    Jul 12, 2013
    Posts:
    11
    You are a god, got rid of that error but came up with another one in the GAFAnimation file.

    Error building Player: Exception: Error: method `System.Collections.Generic.List`1<!!0> System.Collections.Generic.List`1<GAFSequenceData>::ConvertAll<System.String>(System.Converter`2<!0,!!0>)` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Collections.Generic.List`1<System.String> GAFAnimationAsset::getSequenceIDs(System.Int32).

    Code (CSharp):
    1. public List<string> getSequenceIDs(int _TimelineID)
    2.     {
    3.         if (isLoaded &&
    4.             m_SharedData.timelines.ContainsKey(_TimelineID))
    5.         {
    6.             return m_SharedData.timelines[_TimelineID].sequences.ConvertAll(sequence => sequence.name);
    7.         }
    8.         else
    9.         {
    10.             return null;
    11.         }
    12.     }
    I can't read the error to figure out which line of code I need to change or what to add to the code already there.
     
  8. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Yeah I figured that error would still exist. It's in your original post as well. The error is in getSequenceIDs. More specifically looks like a LINQ method (GAFSequenceData.ConvertAll).

    In this case you could change it to use Select which is a LINQ extension method... it's returning a string. So change that return line to this and it should work:

    Code (csharp):
    1.  
    2.   return m_SharedData.timelines[_TimelineID].sequences.Select(sequence => sequence.name);
    3.  
     
  9. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    One other note... ConvertAll is a List<T> specific method. Using .Select actually returns IEnumerable. This is fine because that method returns List<string>. You could easily change the method to return IEnumerable<string> and it would still work (however the code that consumes it may break so I don't recommend it unless you want to do some refactoring). But the benefit of this is that you could actually then use an Array instead of a List. So, it could be called as getSequenceIDs(timelineId).ToArray();

    Or, you could change getSequenceIDs to return an array (string[]) instead of List<string> and then just call .ToArray() after your .Select. If the consuming code isn't using any List specific methods such as .Add, then the array would be more lightweight and may yield better performance depending on how it's being used and how often it's being called. It could be over optimization though so I wouldn't worry about it unless you start neeting to eek out some performance and you find this to be a heavy spot.
     
  10. patrickcummins

    patrickcummins

    Joined:
    Jul 12, 2013
    Posts:
    11
    Cheers for the help man, much appreciated
     
  11. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Did that work then? I'm assuming so.
     
  12. patrickcummins

    patrickcummins

    Joined:
    Jul 12, 2013
    Posts:
    11
    I figured out that I was not using GAF in my code so I just deleted the folder. I thought I was using it for the animation but turns out I wasn't. Thanks for your help do.