Timotheus Pokorra
Timotheus Pokorra

Reputation: 353

Cannot build Newtonsoft.Json.Tests with Mono 4 due to inaccessible internal structs and classes

For Fedora, we want to build Newtonsoft.Json for Mono 4. It would probably be nice to run the tests as well. But when building Newtonsoft.Json.Tests.Net40.csproj, we get errors like this:

Utilities/DateTimeUtilsTests.cs(56,24): error CS0122: `Newtonsoft.Json.Utilities.StringReference' is inaccessible due to its protection level

So checking the source code: https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json.Tests/Utilities/DateTimeUtilsTests.cs#L56 https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/Utilities/StringReference.cs#L30

StringReference is defined as internal struct.

According to https://msdn.microsoft.com/library/7c5ka91b.aspx, "internal types or members are accessible only within files in the same assembly"

So how is this ever going to work? What am I missing? Does this work on MS.NET, but not on Mono?

Upvotes: 0

Views: 66

Answers (1)

Sergey Zhukov
Sergey Zhukov

Reputation: 1372

Internals is visible not only to the assembly where they defined, but also to friendly assemblies. About friendly assemblies you can read in MSDN

In the source code they are defined here and here

Possible you try to run tests with signed version of NewtonSoft.Json.dll and it has different public key from defined in the source (because you signed assembly with your own *.snk file) and this is the reason why Tests assembly does not see internals in the main assembly.

Upvotes: 1

Related Questions