specklesystems / speckle-sharp

.NET SDK, Schema and Connectors: Revit, Rhino, Grasshopper, Dynamo, ETABS, AutoCAD, Civil3D & more.
https://speckle.systems
Apache License 2.0
349 stars 161 forks source link

Alias Newtonsoft #190

Closed teocomi closed 3 years ago

teocomi commented 3 years ago

Newtonsoft.Json is creating conflicts again, we had 2 reports of that happening in GH, so we should alias wherever is possible. Example of how to do so is in the DynamoConnector where we aliased an old version of Newtonsoft that Dynamo uses internally:

https://github.com/specklesystems/speckle-sharp/blob/master/ConnectorDynamo/ConnectorDynamo/ConnectorDynamo.csproj#L66-L69

https://github.com/specklesystems/speckle-sharp/blob/4fb9c8379b8d8a8da9ea2bd1a8f144b8d3e063c4/ConnectorDynamo/ConnectorDynamo/AccountsNode/Accounts.cs#L2

iltabe commented 3 years ago

I got a weird error today doing some tests. Connecting my account to any Stream component in grasshopper, I get this: 1. Method not found: 'Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreIsSpecifiedMembers(Boolean)'.

Might be related? If so the reports are 3. Otherwise ignore me.

teocomi commented 3 years ago

Yep, that's probably due to a Newtosoft conflict, try temporarily disabling your other GH plugins (eg jSwan...) We'll add this item to our backlog for the Beta release!

iltabe commented 3 years ago

I tried to disable all plugins... same error.

iltabe commented 3 years ago

If that helps, the conflict happen when getting the client Speckle.Core.Api.Client(account)

iltabe commented 3 years ago

image

(source: https://discourse.mcneel.com/t/creating-brep-from-json/65873 and my pc)

teocomi commented 3 years ago

Try see if this brings any joy: 295ea734e9a36ba37856263febe72fab61d15971

iltabe commented 3 years ago

No joy. Still getting the same. when calling Speckle.Core.Api.Client(account)

GQLClient = new GraphQLHttpClient(
        new GraphQLHttpClientOptions
        {
          EndPoint = new Uri(new Uri(account.serverInfo.url), "/graphql"),
          UseWebSocketForQueriesAndMutations = false,
          ConfigureWebSocketConnectionInitPayload = (opts) => { return new { Authorization = $"Bearer {account.token}" }; },
          OnWebsocketConnected = OnWebSocketConnect,
        },
        new NewtonsoftJsonSerializer(),
        HttpClient);

Can it be the extternal assembly GraphQL.Client.Serializer.Newtonsoft ?

teocomi commented 3 years ago

Hey @iltabe can you please pull branch newtonsoft-alias and try again?

iltabe commented 3 years ago

Ah, I was writing here while you committed. Test of today was to "delete" JSON dlls in Rhino/System folder. (rhino runs fine...) Running in debug mode, I got still an error, which is not identified nor cached by the debugger. image

Edit: I pull now and try again.

iltabe commented 3 years ago

image

Urrà!

Thanks for the quick fix-support!

teocomi commented 3 years ago

So I got to the bottom of it. The issue was caused by a combination of things:

When Rhino loads it sometimes ignore the N12 dependency and just loads N10, this causes problems in Speckle and in the GQL library. This is especially reproducible when enabling the "Memory load GHA using COFF byt array" setting, as that seems to make Rhino always ignore our N12 dependency.

Solution: The solution found so far consisted in:

Now Speckle can run alongside other GH plugin using earlier versions of Newtonsoft and as well it works well with the COFF setting enabled (see imga below).

Other solutions tried: I also tried aliasing the N12 nuget reference in use by Core but this didn't seem to completely fix the issue, probably because the namespaces of some methods used in N10 and N12 were still the same. This solution also didn't work out nice as the alias wasn't automatically propagated to the other Speckle projects referencig Core and was overall more problematic.

Will close this issue as soon as we approve the solution found.

image