BinaryFormatter trouble Rhino 8

Hi,
I am modifying my plugin to be used with .NET 7 for Rhino 8. For this I also created a Utility project that would contain functionalities to convert different forms of data from the old plugin to the new.

So in the old plugin, I saved data with BinaryFormatter to a file. Since BinaryFormatter is obsolete in .NET 7, I decided to use json instead. In the utility project (which is .net 4.8 Framework), I am trying to deserialize this data using BinaryFormatter, but I constantly get the error
“System.DllNotFoundException: Unable to load DLL ‘rhcommon_c’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)”.

I tried suggestions from here, but didn’t have any progress.

Is the deserialization not possible with a standalone project ? The particular class that I am trying to deserialize is a class with properties of the type Mesh, Plane etc…, though it does not need to do any methods from RhinoCommon for the deserialization.

If this is not possible, is there an alternate way to use the old data in the .NET 7 plugin , or to convert it a compatible format ?

This standalone project, is it a plugin to rhino or completely separate? If it’s separate you’ll still need the Rhino libraries loaded to interact with RhinoCommon (even just deserializing a Point3d class), you’ll likely need to use Rhino.Inside in this standalone project to ensure all of the Rhino libraries are loaded correctly.

1 Like

The utility project is a separate project, though in the same solution as the .net 7 plugin. I create the utility as an executable I call from the new plugin.

Thank you for the suggestion. Let me try that out.

If Rhino Launches it, your issue should be resolved :slight_smile:
Let me know if you have any more questions in your switch from BinaryFormatter to JSON.

I removed all the initial rhinocommon references and installed Rhino.Inside from nuget. I launched the process from Rhino, but got an exception. Added below, with the InnerException:

System.DllNotFoundException: Unable to load DLL ‘rhcommon_c’: A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
at UnsafeNativeMethods.ON_ReadBufferArchive(Int32 archive3dmVersion, UInt32 archiveOnVersion, Int32 length, Byte buffer)
at Rhino.Runtime.CommonObject.SerializeReadON_Object(SerializationInfo info, StreamingContext context)
at Rhino.Runtime.CommonObject…ctor(SerializationInfo info, StreamingContext context)
at Rhino.Geometry.Brep…ctor(SerializationInfo info, StreamingContext context)

It is specifically at the second line of this code that I get the error;

var formatter = new BinaryFormatter();
var data = formatter.Deserialize(stream); ;

Thank you for the help!

Hi @Bovas_Benny,

We’re going to need to see your project to be able to provide help.

– Dale

1 Like

Hi @dale, @CallumSykes
I created a test project to reproduce the issue. Initially I was able to reproduce the exact same exception, though now I do get something related to the Rhino version. If you could take a look to see if the deserialization works in this one, that would be great. I have added a text file with the details of the project.
You can find the project here

1 Like

@Bovas_Benny - your console application needs to stand on it’s own and not reference your Rhino plug-in or any Rhino-included assemblies.

– Dale

I wonder how that is possible, since the ComplexClass uses Rhino geometry classes.

1 Like

is it still an issue with the referecing if I am able deserialize by setting the Mesh and Brep properties to null but a valid Plane value for the ComplexClass properties