Read/write object from .dll

Hi,

I am trying to find the correct structure of my “Spider” project in Visual Studio. Currently I have my SpiderBase-class, and SpiderBaseGoo-class in a separate SpiderGH.dll. My Components, and Parameters are placed in SpiderComponents.gha. In the future I want to create several Components-projects (.gha) and use the goo-baseclass from SpiderGH.dll.

The issue with this structure is that the Read-method on my base-goo is not called when it is placed in a .dll instead of .gha. I suspect that grasshopper only looks in assemblies ending width .gha for deserialization? When I place my goo-baseclass in the .gha-assembly serialization works perfectly. However, this structure prevents me from using the goo-baseclass as an reference in other component-assemblies.

I there an option where I can make grasshopper look in my SpiderGh.dll-assembly on deserialization/read, and would this fix my problem?

image

public abstract class GH_SpiderBaseGoo<T> : GH_GeometricGoo<T>, IGH_PreviewData, IGH_BakeAwareData, GH_ISerializable where T : SpiderBase
.
.
.
  public override bool Write(GH_IWriter writer)
    {
        MemoryStream stream = new MemoryStream();
        IFormatter formatter = new BinaryFormatter();
        formatter.Serialize(stream, Value);
        writer.SetByteArray("SpiderBase", stream.ToArray());
        stream.Close();
        return base.Write(writer);
    }

public override bool Read(GH_IReader reader)
{
    byte[] bytes = reader.GetByteArray("SpiderBase");
    MemoryStream stream = new MemoryStream(bytes);
    IFormatter formatter = new BinaryFormatter();
    Value = (T)formatter.Deserialize(stream);
    stream.Close();
    return base.Read(reader);
}

Best,

Odd Eiken

No really. A .gha is a .dll which has had its extension changed, so you can create your base plugin as .gha and reference it in another project by changing the extension to .dll. But what is normally done is to create both plugins in the same visual studio project, and one of them references the other project. For this to work in Post-build events you must remove the line of code that deletes the .dll after converting it to .gha, so that the second plugin can find that reference.

Than you for the quick response. It seems like this solution works as long as copylocal=false for the referenced assembly to prevent disambiguation between the .dll and .gha.

Use AssemblyResolveEvent

From output log when debuging from VS and loading assemblis in grasshopper:

‘Rhino.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\Users\oddeik\source\repos\Spider\SpiderComponents\bin\SpiderGH.dll’. Symbols loaded.

‘Rhino.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\Users\oddeik\source\repos\Spider\SpiderGH\bin\SpiderGH.gha’. Symbols loaded.

And is followed width this error:

  1. Data conversion failed from Spider to Spider
    image

Is there a best practice for using AssemblyResolveEvent, and would this fix the problem?