GithubHelp home page GithubHelp logo

Comments (12)

Hanning-Liu avatar Hanning-Liu commented on June 17, 2024 1

Thank you for your help! I will continue communicating with Rhino developers!

from messagepack-csharp.

Hanning-Liu avatar Hanning-Liu commented on June 17, 2024

I assume the error is related to memory use. Hope someone and help me!

from messagepack-csharp.

AArnott avatar AArnott commented on June 17, 2024

I don't think we can help you with merely a "MessagePackSerializationException: Failed to serialize MyClass value." as the reported error message.
If you can include the full callstack and all inner exceptions, there's a better chance we can help.

from messagepack-csharp.

Hanning-Liu avatar Hanning-Liu commented on June 17, 2024

Thank you for your reply!

I can't find the full call stack. But I submitted an issue on the Rhino Forum: https://discourse.mcneel.com/t/get-an-error-when-using-c-script-component-to-get-nuget-package/182256/2

I will update this issue once I get any reply from there!

from messagepack-csharp.

Hanning-Liu avatar Hanning-Liu commented on June 17, 2024

@AArnott
Hi, Here is a new reply by the developer of Rhino software. He talks about the possible reason.
https://discourse.mcneel.com/t/get-an-error-when-using-c-script-component-to-get-nuget-package/182256/10?u=hani_leo

The C# Script component continously re-compiles your code every time you make a change. This means that there is an unnamed assembly in memory for every time you have changed the C# script. Each one of these assemblies end up containing a Script_Instance and MyClass implementation.
The MessagePack library you are using in the example above has a dynamic type resolver that based on my quick inspection seem to get confused when the script is changed. It runs fine the first time, but on the second attempt (after editing the script and compiling a new assembly by the component backend), it gets confused on how to resolve and serialize the type MyClass. As I mentioned above this type is now in a completely different assembly but has the same name.
I did not dig deeper into the code behind this library. Here is the the inner exception stack. Seems like there is an exception in the static constructor of the FormatterCache type.

at MessagePack.Resolvers.DynamicObjectResolver.GetFormatter[T]()
   at MessagePack.Resolvers.StandardResolver.FormatterCache`1..cctor()
--- End of stack trace from previous location ---
   at MessagePack.FormatterResolverExtensions.Throw(TypeInitializationException ex)
   at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
   at MessagePack.MessagePackSerializer.Serialize[T](T value, MessagePackSerializerOptions options, CancellationToken cancellationToken)
   at Script_Instance.RunScript(Object x, Object y, Object& a) in rhinocode:///grasshopper/1/bc8f6a2e-38f3-4a28-ab06-7ff244bd8d2a/93d481be-7cf3-445f-af65-5520b5cf9f99:line 63
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

from messagepack-csharp.

AArnott avatar AArnott commented on June 17, 2024

I wonder if the assembly name changes each time it is recompiled and loaded.
If the assembly name is unique each time, I would expect this to work. But if Rhino loads a new assembly with the same name each time, then you're in a decidedly unsupported scenario.

from messagepack-csharp.

Hanning-Liu avatar Hanning-Liu commented on June 17, 2024

Based on what the developer of Rhino said, I think the assemblies have the same name.
And I think the bug should be fixed by the developer of Rhino. Since the C# script component recompiles each time the code is changed, the previously compiled assemblies are no longer useful and should not be stored in memory.

I will continue communicating on the McNeel forum. Thank you for your response!

from messagepack-csharp.

AArnott avatar AArnott commented on June 17, 2024

the previously compiled assemblies are no longer useful and should not be stored in memory.

This may be a runtime limitation. .NET Framework doesn't support unloading assemblies, and I don't think mono does either. The newer ".NET" supports assembly unloading under certain conditions. I wonder which of these Rhino is based on.
Even if supported, unloading the old assembly requires that all references to that assembly be in the same AssemblyLoadContext and unloaded with it. This means MessagePack itself would also have to be loaded into the same ALC and unloaded with it, since MessagePack retains references to all types that it serializes for perf reasons.

from messagepack-csharp.

Hanning-Liu avatar Hanning-Liu commented on June 17, 2024

Rhino runs on .NET Framework on windows and mono on mac before version 8.

Now Rhino 8 on windows supports both .Net Framework 4.8 and .NET 7. I first tried run the MessagePack on .NET 7. But I get these errors, it can't find the attributes:
Untitled-1

So I changed the runtime to .NET Framework, and it only works for the first time as we talked

from messagepack-csharp.

AArnott avatar AArnott commented on June 17, 2024

The attributes not being found isn't a runtime error -- that's an issue with build. Apparently MessagePack.Annotations isn't being referenced by the compiler.

from messagepack-csharp.

Hanning-Liu avatar Hanning-Liu commented on June 17, 2024

Yes, but this is weird. It can recognize all other package without this one.

from messagepack-csharp.

AArnott avatar AArnott commented on June 17, 2024

No denying it's weird... I'm just saying this isn't a MessagePack bug. Rhino is the odd one out here where all the issues are occurring, and MessagePack has proper dependencies between packages so that you shouldn't be getting attribute not found compiler errors, so all arrows point to Rhino being the problem and not something we can support. Sorry.

from messagepack-csharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.