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

ReactJS.MSBuild cannot find Newtonsoft.Json Version=9.0.0. #512

Closed
jadebayo opened this issue Feb 20, 2018 · 16 comments
Closed

ReactJS.MSBuild cannot find Newtonsoft.Json Version=9.0.0. #512

jadebayo opened this issue Feb 20, 2018 · 16 comments
Milestone

Comments

@jadebayo
Copy link

Trying to add React.MSBuild, but when the TransfomrBabel Task is called i get this issue. My project uses Newtonsoft.Json 11.0 and there is a assembly redirect to it.

1> : error MSB4018: The "TransformBabel" task failed unexpectedly.
1> : error MSB4018: React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.IReactSiteConfiguration ---> System.TypeInitializationException: The type initializer for 'React.ReactSiteConfiguration' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
1> : error MSB4018: at React.ReactSiteConfiguration..ctor()
1> : error MSB4018: at React.ReactSiteConfiguration..cctor()
1> : error MSB4018: --- End of inner exception stack trace ---
1> : error MSB4018: at React.ReactSiteConfiguration.get_Configuration()
1> : error MSB4018: at React.AssemblyRegistration.<>c.b__2_0(TinyIoCContainer c, NamedParameterOverloads o)
1> : error MSB4018: at React.TinyIoC.TinyIoCContainer.<>c__DisplayClass29_0`1.b__0(TinyIoCContainer c, NamedParameterOverloads o)
1> : error MSB4018: at React.TinyIoC.TinyIoCContainer.DelegateFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options)
1> : error MSB4018: --- End of inner exception stack trace ---
1> : error MSB4018: at React.TinyIoC.TinyIoCContainer.DelegateFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options)
1> : error MSB4018: at React.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options)
1> : error MSB4018: at React.TinyIoC.TinyIoCContainer.Resolve(Type resolveType)
1> : error MSB4018: at React.TinyIoC.TinyIoCContainer.ResolveResolveType
1> : error MSB4018: at React.MSBuild.TransformBabel.Execute()
1> : error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1> : error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
1> (default targets) -- FAILED.

@dustinsoftware
Copy link
Member

Hi there, I'm not sure if React.MSBuild will work with binding redirects, you might have better luck using a webpack build step instead (see the samples in this repo). Unfortunately I don't have time right now to investigate support for this :/

@Daniel15
Copy link
Member

Daniel15 commented Mar 2, 2018

Unfortunately, MSBuild does not easily support assembly redirects. You'd need to add them to MSBuild.exe.config, and they'd affect all MSBuild calls (not just builds of your project).

Having said that, ReactJS.NET does have a super hacky binding redirect for JavaScriptEngineSwitcher. The way it's implemented is that we override AppDomain.CurrentDomain.AssemblyResolve and manually perform the redirect ourselves (c366e3d). We could likely do that for Newtonsoft.Json too. I'm worried about breaking stuff, as that assembly binding stuff is very fragile.

References:
dotnet/msbuild#1309
http://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/

@dustinsoftware
Copy link
Member

Closing since this question has been answered, feel free to re-open if you'd like some more help.

@ssaroiu
Copy link
Contributor

ssaroiu commented Oct 17, 2018

I'd like to re-open this issue. I have the exact same problem as @jadebayo.

As per this conversation, there are two ways to fix this issue:

  1. Add Newtonsoft.Json to the list of assemblies for which manual redirect is resolved by overriding `AppDomain.CurrentDomain.AssemblyResolve' (as per @Daniel15's comment above). I understand this is brittle, but this hack is already present in the code, and it will fix this problem (I checked).

  2. If the solution is to use webpack instead (as per @dustinsoftware's comment above), I'd suggest to update the relevant documentation. As is, the documentation for React.MSBuild is silent on webpack. Instead, when I follow the documentation, my build fails due to this bug.

References:
https://reactjs.net/bundling/msbuild.html

@dustinsoftware
Copy link
Member

dustinsoftware commented Oct 18, 2018 via email

@dustinsoftware
Copy link
Member

dustinsoftware commented Oct 18, 2018 via email

@ssaroiu
Copy link
Contributor

ssaroiu commented Oct 19, 2018

Both will work for me. How are these two tracked so that I know when they're ready?

Thanks @dustinsoftware.

@kendallb
Copy link

I am trying to get the msbuild task working as well. I think the fundamental issue here is that the msbuild DLL is copied into the output directory as part of the reference to the project, when in reality what would work better is for a working version of the DLL and dependent files to be located in a directory in the nuget package, and run from there rather than the developers bin directory? Running it from the bin directory is going to always lead to failures with incorrect DLL's.

I think the msbuild task could be rebuild to work similarly to how the Razor Generator project does it, which is a project I also use that compiles all the cshtml files in my project down to the .cs files, which are then compiled into the project. The source code is here:

https://github.com/RazorGenerator/RazorGenerator/tree/master/RazorGenerator.MsBuild

@dustinsoftware
Copy link
Member

dustinsoftware commented Jan 31, 2019 via email

@kendallb
Copy link

It will keep coming up, and if the build dll is referenced from the NuGet location then it also removes the need for extra dependencies to be added to my project bin directory. The way razor does it works nicely.

@ssaroiu
Copy link
Contributor

ssaroiu commented Jan 31, 2019

I agree with @kendallb that bumping out the version number is a band-aid rather than a fix. It'll break again couple of months down the road when Newtonsoft updates their JSON.NET nuget.

@kendallb
Copy link

As mentioned, the right solution is to deploy the build DLL into the nuget directory like they do with Razor Generator and run it from there. Then its dependencies are entirely it's own.

@dustinsoftware
Copy link
Member

dustinsoftware commented Jan 31, 2019 via email

@kendallb
Copy link

Yeah I am not sure I am going to go this route anyway. I was desperately trying to avoid using node and packages (gah, I don't like node much!), but I think the better solution for our project is to use Gulp to pre-process all our JSX files at build time and then it will also do all the minification and bundling as well. Just have to bite the bullet I guess and get on the node train ...

@dustinsoftware
Copy link
Member

Going to roll with bumping JSON.NET to 12 in #779. Apps that still need 9.x can remain on the 4.x branch of this library, which we'll backport fixes to. New features we'll put in 5.x.

@dustinsoftware dustinsoftware added this to the 5.0 milestone Apr 29, 2019
@dustinsoftware
Copy link
Member

5.0.0-alpha1 preview published to NuGet, please install from there if you need this support ahead of the release.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants