dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.41k stars 10k forks source link

FileLoadException on IServiceCollection.AddReact() #800

Closed TomGroeneboer closed 9 years ago

TomGroeneboer commented 9 years ago

Hi guys,

I've encountered an issue when adding React to a project. If I try to do services.AddReact() in the ConfigureServices method in the Startup class it throws a FileLoadExeption with the following details: Could not load file or assembly 'React, Version=1.5.0.0, Culture=neutral, PublicKeyToken=9aed67b161f7db78' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)

Does someone know why this happens and how I can resolve it?

I'm running CLR-x86-beta6 in Visual Studio 2015.

Thanks!

davidfowl commented 9 years ago

That's a good question. Do you have repro steps?

TomGroeneboer commented 9 years ago

Just create an empty application with ASP.NET 5, add React following these steps. Note: The services.UseRequestServices() doesn't work, I think it's depricated?

If you try to run the application it comes up with the error :(

davidfowl commented 9 years ago

Those instructions are based on very old versions of ASP.NET 5. Have you contacted them to ask if they have newer versions that are compatible with newer betas of ASP.NET 5.

TomGroeneboer commented 9 years ago

There seems to be an update on NuGet but I can't download it in VS, it only states that version 1.5.3 (and lower) is available...

//// update: I managed to install version 1.5.4, but it still gives me the FileLoadException...

Daniel15 commented 9 years ago

Bumping this because I just got another report of it (also see https://github.com/reactjs/React.NET/issues/153). The exception looks like the following:


System.IO.FileLoadException was unhandled by user code FileName=React, Version=1.5.0.0, Culture=neutral, PublicKeyToken=9aed67b161f7db78 FusionLog="" HResult=-2146234300 Message=Could not load file or assembly 'React, Version=1.5.0.0, Culture=neutral, PublicKeyToken=9aed67b161f7db78' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044) Source=React.AspNet StackTrace: at React.AspNet.ReactServiceCollectionExtensions.AddReact(IServiceCollection services)


The strange thing is that the "React" assembly is strong-named. React.AspNet has a dependency on React.Core which contains React.dll, and I've verified that the latest version does indeed have the correct strong name. Note that ReactJS.NET does not support .NET Core at the moment, so this is only using dnx451.

I haven't been able to replicate the issue myself, everything works as expected for me :worried:

Any ideas what's going on here?

Those instructions are based on very old versions of ASP.NET 5. Have you contacted them to ask if they have newer versions that are compatible with newer betas of ASP.NET 5.

The latest version of ReactJS.NET was built against beta6, I'll release an update for beta7 soon. The instructions were outdated but I updated them a while ago.

davidfowl commented 9 years ago

If you could provide a sample application that has the error that would be great. Can one of your users provide that info?

Daniel15 commented 9 years ago

The two people that have reported it so far are @TomGroeneboer (who originally reported this issue) and @jongalloway (who reported it earlier today).

@jongalloway are you able to provide a sample app that exhibits the issue?

jongalloway commented 9 years ago

Repro is here: https://github.com/jongalloway/react-js-net-repro

All I did was:

  1. File / New / MVC 6 (beta7)
  2. Follow the steps here http://reactjs.net/getting-started/aspnet5.html
  3. Run
Daniel15 commented 9 years ago

Ahh, I see. The issue is that your web project is called "React", but the core ReactJS.NET assembly is also called "React" :laughing: I think the assembly loader gets confused and tries to load your site's assembly rather than the ReactJS.NET assembly. This fails because the assembly React.AspNet referenced at build time was strongly-named, and the strong name doesn't match. If I rename your project from "React" to "Reactizzle", I don't get the strong typing error any more (I do get a different unrelated error, which is because the latest release of ReactJS.NET was build against beta6 rather than beta7. The latest master version does support beta 7).

I tried the same thing with ASP.NET 4.5 + MVC 5, and the error is the one I would have expected: "Could not load file or assembly 'React, Version=1.5.0.0, Culture=neutral, PublicKeyToken=9aed67b161f7db78' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. " In this case the assembly bind log shows more details that help to debug the issue:

LOG: Attempting download of new URL file:///c:/users/danlo/documents/visual studio 2015/Projects/ReactBug/React/bin/React.DLL. WRN: Comparing the assembly name resulted in the mismatch: Minor Version

It seems like ASP.NET 5 still tries to load the assembly even though the version number doesn't match, resulting in a more confusing error message.

davidfowl commented 9 years ago

We had the same problems a long time ago in signalr, then we called it Microsoft.AspNet.SignalR

Daniel15 commented 9 years ago

@davidfowl - It may be an edge case, but can the loader guard against this somehow (a referenced assembly having the same name as the site itself)?

davidfowl commented 9 years ago

We don't look at strong names when loading assemblies. We could probably fail if 2 things have the same name in the graph but it's not something we're going to do in the short term.

jjkopmels commented 9 years ago

Hi Guys,

this is still not working on my end, freshly installed vs2015, running beta7, empty new solution, mvc6 project, followed the instructions here http://reactjs.net/getting-started/aspnet5.html, run the project and getting the same error.... the error does not occur when cloning the git repo to my local disk, building it and then opening and running the mvc6 demo inside vs2015.... what config thingy am i missing here?

BTW: none of the items, solution or project are called anything like react....

Daniel15 commented 9 years ago

@jjkopmels Can you please provide a full stack trace of the exception?

jjkopmels commented 9 years ago

@Daniel15 sure:

System.IO.FileNotFoundException was unhandled by user code FileName=Microsoft.Framework.Runtime.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null FusionLog==== Pre-bind state information === LOG: DisplayName = Microsoft.Framework.Runtime.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///C:/Users/jan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta7/bin LOG: Initial PrivatePath = NULL

Calling assembly : (Unknown).

LOG: This bind starts in default load context. LOG: Using application configuration file: c:\Users\jan\documents\visual studio 2015\Projects\testert\src\testert\wwwroot\Web.config LOG: Using host configuration file: C:\Users\jan\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Users/jan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta7/bin/Microsoft.Framework.Runtime.Abstractions.DLL. LOG: Attempting download of new URL file:///C:/Users/jan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta7/bin/Microsoft.Framework.Runtime.Abstractions/Microsoft.Framework.Runtime.Abstractions.DLL. LOG: Attempting download of new URL file:///C:/Users/jan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta7/bin/Microsoft.Framework.Runtime.Abstractions.EXE. LOG: Attempting download of new URL file:///C:/Users/jan/.dnx/runtimes/dnx-clr-win-x86.1.0.0-beta7/bin/Microsoft.Framework.Runtime.Abstractions/Microsoft.Framework.Runtime.Abstractions.EXE.

HResult=-2147024894 Message=Could not load file or assembly 'Microsoft.Framework.Runtime.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Source=React.AspNet StackTrace: at React.AspNet.ReactBuilderExtensions.UseReact(IApplicationBuilder app, Action`1 configure, JsxFileOptions fileOptions) at testert.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in C:\Users\jan\Documents\Visual Studio 2015\Projects\testert\src\testert\Startup.cs:line 112 InnerException:

Daniel15 commented 9 years ago

@jjkopmels That's a different error, it's because the current release version of ReactJS.NET only supports beta 6. The version in the repo supports beta 7 but you need to build it yourself at the moment. I'll post a beta 7 update soon.

Daniel15 commented 9 years ago

I just uploaded ReactJS.NET 1.5.5 which supports beta 7 :)

kilanny commented 8 years ago

Turned out I added reference (normal) while should be COMReference instead in project file. Very strange problem.

Find out the latest word revealed by God for humankind guidance ! Read Quran now http://quran.com/25