-
Notifications
You must be signed in to change notification settings - Fork 231
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
Could not load file or assembly 'System.Security.Permissions..' when building projects with dotnet
#4808
Comments
when building projects with
dotnet`dotnet
Let's just remove the dependency. I took a look at the lightweight implementation I did some time ago: |
Ok, this seems like a feature to replace JSON parsing. We could even just do a string search in JSON files and not care about the parsing. Do we really need proper JSON parsing for good-enough results? (search a substring - the json attribute we're looking for; eat all spaces after and see what's next - the attribute value). Later edit: well we also need the context... so we actually need the JSON parsing :( We can also consider using
Newtonsoft.JSON https://www.nuget.org/packages/Newtonsoft.Json/ - 1.97 MB |
@costin-zaharia-sonarsource do you have a repro project uploaded somewhere? |
I'm afraid that replacing a dependency with another will not solve our issue. There will still be problems for users who have common dependencies. |
Yes, there is one added by the original issue reporter. You can find it here: https://github.com/AquilaSands/sonarcloud-build-fail-repro |
I'm not sure here. The culprit here is the fact that Newtonsoft relies on Code Access Security, which stopped being supported in .NET Core and was obsoleted in .NET 5 (docs). It was part of the runtime in .NET Framework, in .NET Core the API was kept but did nothing and in .NET 5 it was removed (from my understanding). Either way, by using a library with less dependencies, IMO we will reduce the risk of conflict while avoiding adding JSON parsing logic in the analyzer. |
Indeed, by using a library with fewer dependencies we will reduce the risks. From another point of view, the compiler will always use the version of the assembly we provide and the one referenced by the client code will be ignored, and, as long as this is happening, we will never be able to have a 100% reliable solution since breaking changes or functional ones can happen in the same library from one version to another. |
In the end we've decided, for the moment, to bundle newtonsoft inside the DLL (the MIT license allows for it) and to stop providing the nuget as a dependency. Mid-term we should add a simple JSON parser inside our analyzer and drop the need for newtonsoft altogether (and we'll save some hundreds of KBs in DLL size). |
This looks good to me. Repackaging the dependency will avoid conflicts with other user-added dependencies. |
Coming back on this - #4888 will fix the Newtonsoft problem, but it won't fix conflicts with Google.protobuf. So we'll still need to ILMerge the protobuf library, right @costin-zaharia-sonarsource @pavel-mikula-sonarsource ? |
In theory yes, but do we have a problem with |
@pavel-mikula-sonarsource we'll be able to answer after the SONARSEC-2690 investigation. |
Theoretically, as long as we have dependencies (even to our packages) we let the door open for this kind of issues. In practice, the chance is not that high for Personally, I would prefer to embed |
see page 3 in this doc - “The Linking Debate” on being a derivative work of the OSS library or not depending on the linking strategy - we'll need to carefully read the software licenses |
Fixed in #5049 |
today i had same issue |
Hi @Harishapc - your feedback is valuable - you can open a topic on https://community.sonarsource.com/ and say the solution that you have found. |
Source: https://community.sonarsource.com/t/azure-devops-pipeline-build-fails-with-sonarcloud-and-source-generator/45725
Context:
sonar-dotnet
embeds theNewtonsoft.Json.dll
library compiled for net45.Stack Trace:
The problem appears when JsonTypeReflector.get_DynamicCodeGeneration is called since .Net Core tries to resolve
SecurityPermission
fromSystem.Security.Permissions.dll
which cannot be found. Source code: https://github.com/JamesNK/Newtonsoft.Json/blob/11.0.2/Src/Newtonsoft.Json/Serialization/JsonTypeReflector.cs#L449The type was made obsolete starting with .Net 5: https://docs.microsoft.com/en-us/dotnet/api/system.security.permissions.securitypermission?view=net-5.0
There seem to be differences when building with MSBuild vs dotnet since MSBuild will not even try to load the
System.Security.Permissions.dll
assembly.I’ve done a short test and, if I embed the netstandard2.0 version of
Newtonsoft.Json.dll
, I can build the repro project without any problems. The limitation with this approach is that we will have compatibility issues with older versions of Visual Studio.As far as I can tell the compiler will always load the version of Newtonsoft.Json we provide. Seems to be related to this issue: dotnet/roslyn#41421.
One possible solution is to remove the dependency on
Json.Net
.The text was updated successfully, but these errors were encountered: