Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias Newtonsoft #190

Closed
teocomi opened this issue Jan 15, 2021 · 11 comments · Fixed by #198
Closed

Alias Newtonsoft #190

teocomi opened this issue Jan 15, 2021 · 11 comments · Fixed by #198
Assignees
Labels
bug Something isn't working grasshopper issues related to the grasshopper connector. rhino

Comments

@teocomi
Copy link
Member

teocomi commented Jan 15, 2021

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

using DNJ = DynamoNewtonsoft::Newtonsoft.Json;

@teocomi teocomi added the bug Something isn't working label Jan 15, 2021
@didimitrie didimitrie added grasshopper issues related to the grasshopper connector. rhino labels Jan 19, 2021
@iltabe
Copy link

iltabe commented Jan 25, 2021

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
Copy link
Member Author

teocomi commented Jan 25, 2021

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!

@teocomi teocomi self-assigned this Jan 25, 2021
@iltabe
Copy link

iltabe commented Jan 26, 2021

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

@iltabe
Copy link

iltabe commented Jan 26, 2021

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

@iltabe
Copy link

iltabe commented Jan 26, 2021

@teocomi
Copy link
Member Author

teocomi commented Jan 26, 2021

Try see if this brings any joy: 295ea73

@iltabe
Copy link

iltabe commented Jan 26, 2021

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
Copy link
Member Author

teocomi commented Jan 27, 2021

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

@iltabe
Copy link

iltabe commented Jan 27, 2021

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
Copy link

iltabe commented Jan 27, 2021

image

Urrà!

Thanks for the quick fix-support!

@teocomi
Copy link
Member Author

teocomi commented Jan 27, 2021

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

  • Speckle requires Newtonsoft 12+
  • the GraphQL library in use by Speckle also requires Newtonsoft 12+
  • Rhino requires Newtonsoft 10
  • various GH plugins come with earlier versions of Newtonsoft as well (eg jSwan)

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:

  • creating a Speckle.Newtonsoft.Json package with updated namespaces, this was also published on NuGet (manually)
  • replacing throughout speckle-sharp Newtonsoft.Json in favour of Speckle.Newtonsoft.Json
  • replacing the GraphQL NewtonsoftJsonSerializer class with a copy of the same also referencing Speckle.Newtonsoft.Json

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working grasshopper issues related to the grasshopper connector. rhino
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants