Показать сообщение отдельно
Старый 24.01.2016, 15:19   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Axilicious:CombineXpos.exe Length cannot be less than zero
Источник: http://www.ksaelen.be/wordpresses/dy...ess-than-zero/
==============

When I was using the combineXPOs.exe executable the other day on a new project, I ran into an issue. The error message thrown by the tool was the following:



CombineXPOs.exe : Warning [-5] CombineXPOs.exe : Error [] Length cannot be less than zero.



I remembered that Martin Dráb ran into the same error previously so I went to take a look at his blog post on this type of error. In his post, he explains this might be because of empty / corrupted XPO files and indeed, this error pops up when you either have an empty XPO file or a (corrupted) shared project node that contains no objects.


Removing 2 of 6000+ XPO files that turned out to be empty indeed helped and the tool got further in the list of XPO files. But wait, it still gave the same error message?! So what was different here? I saw that the error code being returned was not -4, but -5. And I did not have empty XPO files anymore. And on top of that, now it was the directory with all the Shared Project XPO files that returned errors.

I couldn’t see right away what the issue was here, so I decided to peek into the executable and reverse engineer a C# project out of it. The I stepped through the process of combining a single file and managed to see what was going on. Somewhere inside there, there is an XPOReader class that opens the XPO files and looks at the encoding of the files.


X++:
if (fileStream.Length > 3L &&(int)numArray[0] == 239 && ((int)numArray[1] == 187 && (int)numArray[2] == 191))
{
    this.fileEncoding = (Encoding)this.utf8Encoding;
    num1 = 1;
}
else
{
    this.fileEncoding = Encoding.GetEncoding(1252);
}
Looking at the code, it turns out that it looks for UTF8 files, and if that is not the case, assumes it has to be CP1252 (Latin 1). What if my files have another encoding? And looking at the files, they turned out to be LCS-2 LE BOM. Until now, I haven’t looked into it why these project XPO files have a different encoding. To solve the issue in this case, a bit of additional code makes sure the XPO reader can correctly read the XPO through codepage 1200.


X++:
if (fileStream.Length > 3L && (int)numArray[0] == 239 && ((int)numArray[1] == 187 && (int)numArray[2] == 191))
{
    this.fileEncoding = (Encoding)this.utf8Encoding;
    num1 = 1;
}
else
{
    // KeSae : Check for codepage UCS-2 LE
    if (numArray[0] == 0xFF && numArray[1] == 0xFE)
    {
        this.fileEncoding = Encoding.GetEncoding(1200);
    }
    else
    {
        this.fileEncoding = Encoding.GetEncoding(1252);
    }
}
Rebuilding the project resulted in a customized CombineXPOs.exe executable that correctly handles the shared project nodes in



Источник: http://www.ksaelen.be/wordpresses/dy...ess-than-zero/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.

Последний раз редактировалось mazzy; 25.01.2016 в 16:27.