# \[c api\] SU\_ERROR\_SERIALIZATION

**URL:** <https://forums.sketchup.com/t/c-api-su-error-serialization/101771>\
**Category:** SketchUp SDK\
**Created:** [August 27, 2019, 10:19am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771 "2019-08-27T10:19:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [August 27, 2019, 10:19am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/1 "2019-08-27T10:19:32Z")

</div>

Can we have a bit more information regarding this error:  
`SU_ERROR_SERIALIZATION if the serialization operation itself fails`

It happens in SUModelSaveToFileWithVersion() when trying to create a very large SketchUp file. I’m not sure of the exact size it would be, but probably in the realm of several GBs. Is there a file size limit the SDK can produce?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [August 28, 2019, 2:12am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/2 "2019-08-28T02:12:58Z")

</div>

> [@jiminybillybob](#):
>
> serialization

I bothered Thomas about this last year in a tracking issue …

> <https://github.com/SketchUp/api-issue-tracker/issues/71>
>
> \### C API Documentation Issue
> 
> \#### \[\*\*\`SUComponentInstanceSaveAs()\`\*\*\](https:…//extensions.sketchup.com/developers/sketchup\_c\_api/sketchup/struct\_s\_u\_component\_instance\_ref.html#add89b2be37466aa7499213e5289911cd)
> 
> \> \*\*DEPRECATED\*\*: at API v10.0, SketchUp release 2022.0
> New code should update to API v10.0 (or higher) and use the \[\`SUComponentDefinitionSaveToFile()\`\](https://extensions.sketchup.com/developers/sketchup\_c\_api/sketchup/struct\_s\_u\_component\_definition\_ref.html#a98735078e64bf09c9f6ff04d295b9b88) function.
> 
> The 2nd parameter ...
> \`\[in\]	file\_path	The file path destination of the serialization operation. Assumed to be UTF-8 encoded.
> \`
> 
> What does \*\*\_serialization\_\*\* mean here ?
> 
> Is this function meant to save out to a component SKP file ?
> 
> \----
> 
> Confused because the Ruby API has \*\*no\*\* "save\_as" method for the Instance class, but \*\*does\*\* have one for the Definition class. The C API has a "save\_as" for the Instance object but \*\*not\*\* the Definition.
> 
> \> \*\*NOTE\*\*: Fixed at API v10.0 with addition of the \[\`SUComponentDefinitionSaveToFile()\`\](https://extensions.sketchup.com/developers/sketchup\_c\_api/sketchup/struct\_s\_u\_component\_definition\_ref.html#a98735078e64bf09c9f6ff04d295b9b88) function.
> 
> So referring to my "Scenario 2" in: https://github.com/SketchUp/api-issue-tracker/issues/70#issuecomment-375902656, it looks as though there is only a Ruby solution at present, for a batch mode means of correcting incorrectly nested DC files.
> 
> \> \*\*EDIT\*\*: (2022-01-27) Revisiting, it appears that this would be doable since SketchUp 2019.2, API 7.1, when the ability to remove the unneeded wrapping definition was added with the \[\`SUModelRemoveComponentDefinitions()\`\](https://extensions.sketchup.com/developers/sketchup\_c\_api/sketchup/struct\_s\_u\_model\_ref.html#a33a670a5502718627a555e645e0e406a) function.
> .
> Before the definition removal, a copy of the nested DC instance would need to be added to the model's entities collection at the origin, and any (especially dynamic) attribute dictionaries copied to the new instance.
> .
> The dictionary copying chore could be avoided if running API v10.0, SketchUp release 2022.0 (or higher) and use the \[\`SUComponentDefinitionSaveToFile()\`\](https://extensions.sketchup.com/developers/sketchup\_c\_api/sketchup/struct\_s\_u\_component\_definition\_ref.html#a98735078e64bf09c9f6ff04d295b9b88) function to save out the nested DC to a standalone file, then close and delete the "wrapped" component file. Lastly rename the new "unwrapped" DC component file in the local component collection folder to the old name.

I suggest you add any other methods where this “serialization” is mentioned.

I suspect it just mean whilst writing to the file’s DOM tree.

---

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [August 28, 2019, 7:30am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/3 "2019-08-28T07:30:35Z")

</div>

One possibility: I see this when I attempt to write a model file that is already open in SketchUp.

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [August 28, 2019, 9:09am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/4 "2019-08-28T09:09:45Z")

</div>

In this case, the file doesn’t exist yet.

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [August 28, 2019, 9:34am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/5 "2019-08-28T09:34:28Z")

</div>

`SU_ERROR_SERIALIZATION` is returned if:

- The target path is not writable
- The save operation failed (the internal call to save the model yields `false`. there is no further details given back to the API)

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [August 28, 2019, 11:51am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/6 "2019-08-28T11:51:22Z")

</div>

> [@tt\_su](#):
>
> (there is no further details given back to the API)

☹

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [August 28, 2019, 12:28pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/7 "2019-08-28T12:28:10Z")

</div>

Are you able to provide a simple repro? I can then run it through the debugger and see where it fails.

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [August 28, 2019, 2:55pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/8 "2019-08-28T14:55:57Z")

</div>

No, we’re able to reproduce it only with a single large FBX model loaded in Transmutr

If I provide a Transmutr license and the model, can you run the debugger?

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [August 29, 2019, 8:56am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/9 "2019-08-29T08:56:04Z")

</div>

I can try.

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [September 2, 2019, 11:29am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/10 "2019-09-02T11:29:46Z")

</div>

Does the C API contain debug symbols?

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [September 3, 2019, 9:36am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/11 "2019-09-03T09:36:35Z")

</div>

Afraid we cannot distribute that - would expose too much of our internals.

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [September 3, 2019, 11:40am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/12 "2019-09-03T11:40:45Z")

</div>

Ok, so I guess the debugger won’t tell you much…

If you still want to try, I believe you have a Transmutr license. PM me if you can’t find it.

The model is here: [Cant get a sketchup file generated from this model - Bug reports - Lindalë forums](https://forums.lindale.io/t/cant-get-a-sketchup-file-generated-from-this-model/1917)

Does it help if I give you a version of Transmutr with our own debug symbols?

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [September 4, 2019, 6:40am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/13 "2019-09-04T06:40:50Z")

</div>

Oh I just realized, you can swap DLLs?  
In Transmutr, SketchUpAPI.dll is located in:

- `C:\Program Files\Transmutr\resources\app.asar.unpacked\_webpack` if installed “per-machine”
- `C:\Users\thomthom\AppData\Local\Programs\Transmutr\resources\app.asar.unpacked\_webpack` if installed “per-user”

Let me know if you need anything else.

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [September 4, 2019, 9:23am UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/14 "2019-09-04T09:23:24Z")

</div>

One more thing.  
We use Electron, so the easiest is to attach the debugger once Transmutr is already launched. Electron uses multiple processes, so you might need to try a few of them. Usually, the first process in the debugger selection window is the one, but that’s not true 100% of the time.

 ![debugger](https://global.discourse-cdn.com/sketchup/original/3X/d/1/d1c505299fc8caaa74370753ac8cacf3f667bccb.png)

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [November 22, 2019, 4:19pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/15 "2019-11-22T16:19:17Z")

</div>

@tt_su Where you able to take a look at this?

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [November 25, 2019, 1:04pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/16 "2019-11-25T13:04:15Z")

</div>

> [@jiminybillybob](#):
>
> C:\Users\thomthom\AppData\Local\Programs\Transmutr\resources\app.asar.unpacked\_webpack

Looking now.

How long does the export usually take before it crashes? (Been running for a while now. Transmutr’s memory usage is up at ~8GB)

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [November 25, 2019, 1:05pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/17 "2019-11-25T13:05:42Z")

</div>

…and it just completed without crashing.

I loaded the FBX from that other thread and exported as SKP without adjusting anything.

---

<div class="post-metadata">

**Author:** ![jiminybillybob](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jiminybillybob/32/197139_2.png) [@jiminybillybob](https://forums.sketchup.com/u/jiminybillybob)\
**Post date:** [November 25, 2019, 2:52pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/18 "2019-11-25T14:52:47Z")

</div>

Transmutr doesn’t crash, but `SUModelSaveToFileWithVersion()` returns `SU_ERROR_SERIALIZATION `

We handle the error to avoid a crash, but no .skp file is being generated. That’s what I was asking: can you check why we get `SU_ERROR_SERIALIZATION` in this case?

Thanks for looking into this!

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [November 25, 2019, 4:13pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/20 "2019-11-25T16:13:39Z")

</div>

It’s failing to copy the temp file to the target location for some reason.

I see the temp `skp*` file being written to `C:\Users\tthomas2\AppData\Local\Temp` - but post-write checks for the file before copying fails.

When I tried to copy the temp file to my desktop and append `.skp` to it SketchUp appear to crash. So I’m not sure yet what is causing all this. The file is ~2.5 GB - I’m not sure if the filesize itself is causing problems with some of the system file functions we are calling…

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [November 25, 2019, 4:23pm UTC](https://forums.sketchup.com/t/c-api-su-error-serialization/101771/21 "2019-11-25T16:23:24Z")

</div>

Hm… The written file is `2 565 944 356` bytes… And before copying the temp file we use `_wstat` which according to MS docs says supports only 32bit file lengths: [\_stat, \_stat32, \_stat64, \_stati64, \_stat32i64, \_stat64i32, \_wstat, \_wstat32, \_wstat64, \_wstati64, \_wstat32i64, \_wstat64i32 | Microsoft Learn](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019)

I’ll to more tests tomorrow, but I suspect this is the culprit. (I tried to load the temp file again, and this time it worked.)

If this is the case, then I think the only workaround you can use right now is to check the temp directory for a `skp*` (`skp2` or `skp3` etc.) is try to manually move it after a failed serialization. It’s a bit fragile and relies on implementation details, so mileage might vary. At least you can instruct your users to try to manually recover the file.

[Next page](https://forums.sketchup.com/t/c-api-su-error-serialization/101771.md?page=2)
