How to deserialize a style blob (style-File => mdb) into an arcobjects-object (.NET C#) (and back)?

670
0
06-24-2020 07:06 AM
FlorianHoffmann2
New Contributor II

Hello,

I have to extract the styles from a style file into an arcobjects-object in C# but I'm a little bit stuck.

What I know so far:

* a style-file is a mdb

* all meta-informations are stored in clear-text fields inside the tables

* the actual style-informations are stored as binary-blob in the "Object-Field"

I can easily read the style-file with the "Microsoft-JET"-driver:

var conStringOledb = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={path};Persist Security Info=False;";

Now comes the tricky part. I think the binary data consist of three parts:

  1. 4 bytes for the length of the data
  2. 16 bytes for the guid
  3. the rest => data

So I transfered the guid + data parts in a memory-stream and hoped for the best:

object objectDeserialize = binaryFormatter.Deserialize(memoryStream);

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 ..."

(The input stream is not a valid binary format. The starting contents (in bytes) are: ...)

Also I tried to manually check the guid to ensure it's the right one:

var len =bytes.Take(4).ToArray();
 var guid = bytes.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());

This one is based on the slyr-python-package. Which can import style-files into qgis.

But the created GUID is nowhere to be near the expected value.

Can anybody give me a hint/clue, what to do, what I have to watch out for?

Resources:

GitHub - nyalldawson/slyr: A Python ESRI lyr/style file converter/extracter/parser 

How To: Implement IPersistStream in a .NET class 

0 Kudos
0 Replies