Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
440 stars 49 forks source link

Make Exception serializable #22

Closed huan086 closed 7 years ago

huan086 commented 7 years ago

I'm running JavaScript in my Entity Framework seed method. When an exception occurs, it throws Type 'JavaScriptEngineSwitcher.Core.JsEngineLoadException' in assembly 'JavaScriptEngineSwitcher.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=c608b2a8cc9e4472' is not marked as serializable.

So make exceptions serializable. See https://blogs.msdn.microsoft.com/agileer/2013/05/17/the-correct-way-to-code-a-custom-exception-class/

Taritsyn commented 7 years ago

Hello, Huan!

I will fix this problem in the next release.

You have found the cause of the JsEngineLoadException? What JS engine are you using?

huan086 commented 7 years ago

JsEngineLoadException was due to the new nuget package not having the native DLLs bundled by default. Installed the 2 native packages and the error went away.

Using ClearScript V8

Taritsyn commented 7 years ago

OK

Daniel15 commented 7 years ago

Note that .NET Core doesn't have binary serialization, so you need to use conditional comments like this to only include the Serializable attribute (and constructor with SerializationInfo and StreamingContext) on .NET Framework and not .NET Core:

#if NET40 || NET45
    [Serializable]
#endif

eg. see https://github.com/reactjs/React.NET/blob/89bc9cbecef5e549f746d645d42706aa3a6d3219/src/React.Core/Exceptions/BabelException.cs#L18

Taritsyn commented 7 years ago

Hello, Huan!

In JavaScript Engine Switcher 2.1.2 fixed this error.