<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to deserialize a style blob (style-File =&amp;gt; mdb) into an arcobjects-object (.NET C#) (and back)? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-deserialize-a-style-blob-style-file-gt-mdb/m-p/48772#M1245</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;to extract the&amp;nbsp;styles from a style file into an arcobjects-object in C# but I'm a little bit stuck.&lt;/P&gt;&lt;P&gt;What I know so far:&lt;/P&gt;&lt;P&gt;* a style-file is&amp;nbsp;a mdb&lt;/P&gt;&lt;P&gt;* all meta-informations are stored in clear-text fields inside the tables&lt;/P&gt;&lt;P&gt;* the actual style-informations are stored as binary-blob in the "Object-Field"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can easily read the style-file with the "Microsoft-JET"-driver:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var conStringOledb = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={path};Persist Security Info=False;";&lt;/PRE&gt;&lt;P&gt;Now comes the tricky part. I think the binary data&amp;nbsp;consist of&amp;nbsp;three parts:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;4 bytes for the length of the data&lt;/LI&gt;&lt;LI&gt;16 bytes for the guid&lt;/LI&gt;&lt;LI&gt;the rest =&amp;gt; data&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;So I transfered the guid + data parts in a memory-stream and hoped for the best:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;object objectDeserialize = binaryFormatter.Deserialize(memoryStream);&lt;/PRE&gt;&lt;P&gt;But it won't work: System.Runtime.Serialization.SerializationException: "Der Eingabedatenstrom hat kein gültiges binäres Format. Die Startinhalte (in Bytes) sind: 92-C8-D0-11-8B-B6-08-00-09-EE-4E-41-02-00-0D-00-00 ..."&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;(The input stream is not a valid binary format. The starting contents (in bytes) are: ...&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also&amp;nbsp;I tried to manually check the guid to ensure it's the&amp;nbsp;right one:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var len =bytes.Take(4).ToArray();
 var guid = &lt;SPAN&gt;bytes&lt;/SPAN&gt;.Skip(4).Take(16).ToArray();

var guidString = BitConverter.ToString(guid).Replace("-", string.Empty);

var sb = new StringBuilder();
 sb.Append(guidString.Substring(6, 2));
 sb.Append(guidString.Substring(4, 2));
 sb.Append(guidString.Substring(2, 2));
 sb.Append(guidString.Substring(0, 2));
 sb.Append("-");
 sb.Append(guidString.Substring(10, 2));
 sb.Append(guidString.Substring(8, 2));
 sb.Append("-");
 sb.Append(guidString.Substring(14, 2));
 sb.Append(guidString.Substring(12, 2));
 sb.Append("-");
 sb.Append(guidString.Substring(16, 4));
 sb.Append("-");
 sb.Append(guidString.Substring(20));

var guidObj = Guid.Parse(sb.ToString());&lt;/PRE&gt;&lt;P&gt;This one is based on the slyr-python-package. Which can&amp;nbsp;import style-files into qgis.&lt;/P&gt;&lt;P&gt;But the created GUID is nowhere to be near the expected value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody give me a hint/clue, what to do, what&amp;nbsp;I have to watch out for?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Resources:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://github.com/nyalldawson/slyr" title="https://github.com/nyalldawson/slyr" rel="nofollow noopener noreferrer" target="_blank"&gt;GitHub - nyalldawson/slyr: A Python ESRI lyr/style file converter/extracter/parser&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://support.esri.com/en/technical-article/000009026" title="https://support.esri.com/en/technical-article/000009026" rel="nofollow noopener noreferrer" target="_blank"&gt;How To: Implement IPersistStream in a .NET class&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 15:57:45 GMT</pubDate>
    <dc:creator>FlorianHoffmann2</dc:creator>
    <dc:date>2021-12-12T15:57:45Z</dc:date>
    <item>
      <title>How to deserialize a style blob (style-File =&gt; mdb) into an arcobjects-object (.NET C#) (and back)?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-deserialize-a-style-blob-style-file-gt-mdb/m-p/48772#M1245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have&amp;nbsp;to extract the&amp;nbsp;styles from a style file into an arcobjects-object in C# but I'm a little bit stuck.&lt;/P&gt;&lt;P&gt;What I know so far:&lt;/P&gt;&lt;P&gt;* a style-file is&amp;nbsp;a mdb&lt;/P&gt;&lt;P&gt;* all meta-informations are stored in clear-text fields inside the tables&lt;/P&gt;&lt;P&gt;* the actual style-informations are stored as binary-blob in the "Object-Field"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can easily read the style-file with the "Microsoft-JET"-driver:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var conStringOledb = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={path};Persist Security Info=False;";&lt;/PRE&gt;&lt;P&gt;Now comes the tricky part. I think the binary data&amp;nbsp;consist of&amp;nbsp;three parts:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;4 bytes for the length of the data&lt;/LI&gt;&lt;LI&gt;16 bytes for the guid&lt;/LI&gt;&lt;LI&gt;the rest =&amp;gt; data&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;So I transfered the guid + data parts in a memory-stream and hoped for the best:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;object objectDeserialize = binaryFormatter.Deserialize(memoryStream);&lt;/PRE&gt;&lt;P&gt;But it won't work: System.Runtime.Serialization.SerializationException: "Der Eingabedatenstrom hat kein gültiges binäres Format. Die Startinhalte (in Bytes) sind: 92-C8-D0-11-8B-B6-08-00-09-EE-4E-41-02-00-0D-00-00 ..."&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;(The input stream is not a valid binary format. The starting contents (in bytes) are: ...&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also&amp;nbsp;I tried to manually check the guid to ensure it's the&amp;nbsp;right one:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var len =bytes.Take(4).ToArray();
 var guid = &lt;SPAN&gt;bytes&lt;/SPAN&gt;.Skip(4).Take(16).ToArray();

var guidString = BitConverter.ToString(guid).Replace("-", string.Empty);

var sb = new StringBuilder();
 sb.Append(guidString.Substring(6, 2));
 sb.Append(guidString.Substring(4, 2));
 sb.Append(guidString.Substring(2, 2));
 sb.Append(guidString.Substring(0, 2));
 sb.Append("-");
 sb.Append(guidString.Substring(10, 2));
 sb.Append(guidString.Substring(8, 2));
 sb.Append("-");
 sb.Append(guidString.Substring(14, 2));
 sb.Append(guidString.Substring(12, 2));
 sb.Append("-");
 sb.Append(guidString.Substring(16, 4));
 sb.Append("-");
 sb.Append(guidString.Substring(20));

var guidObj = Guid.Parse(sb.ToString());&lt;/PRE&gt;&lt;P&gt;This one is based on the slyr-python-package. Which can&amp;nbsp;import style-files into qgis.&lt;/P&gt;&lt;P&gt;But the created GUID is nowhere to be near the expected value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anybody give me a hint/clue, what to do, what&amp;nbsp;I have to watch out for?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Resources:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://github.com/nyalldawson/slyr" title="https://github.com/nyalldawson/slyr" rel="nofollow noopener noreferrer" target="_blank"&gt;GitHub - nyalldawson/slyr: A Python ESRI lyr/style file converter/extracter/parser&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://support.esri.com/en/technical-article/000009026" title="https://support.esri.com/en/technical-article/000009026" rel="nofollow noopener noreferrer" target="_blank"&gt;How To: Implement IPersistStream in a .NET class&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:57:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-deserialize-a-style-blob-style-file-gt-mdb/m-p/48772#M1245</guid>
      <dc:creator>FlorianHoffmann2</dc:creator>
      <dc:date>2021-12-12T15:57:45Z</dc:date>
    </item>
  </channel>
</rss>

