Javascriptservices: Application running on NET461 fails with FileLoadException

Created on 3 Dec 2016  路  15Comments  路  Source: aspnet/JavaScriptServices

Attempting to get the sample running works for a .NET CORE app but fails in NET461.

Sample repro

When running a very simple page that contains

<div id="my-spa" asp-prerender-module="ClientApp/boot-server"></div>

The application will fail with:

System.IO.FileLoadException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at System.Net.Http.WinHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.PostAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.PostAsync(String requestUri, HttpContent content, CancellationToken cancellationToken)
at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.d__71.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.d__131.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.d__101.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft.AspNetCore.SpaServices.Prerendering.PrerenderTagHelper.d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at AspNetCore._Views_Home_Index_cshtml.d__28.MoveNext() in /Views/Home/Index.cshtml:line 2
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.ViewResult.d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__30.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()

Removing the _asp-prerender-module_ attribute and refreshing the page and everything runs just fine.

Most helpful comment

I just got this issue after upgrading to VS 2017 :(
Using System.Net.Http 4.3.1 solved it...
but how come just upgrade VS is causing that issue?

All 15 comments

@MarkPieszak That's not correct - the NodeServices/SpaServices packages should work completely on .NET Framework 4.5.1 and later (as well as .NET Core). It requires ASP.NET Core (not classic ASP.NET), but ASP.NET Core (the application framework) can run on both .NET Core and .NET Framework 4.5.1+ (the runtime platform). I know the naming is very tricky, so I can understand the confusion!

@lruckman Sorry for the inconvenience. I can repro the issue and am trying to track down what's going on with that. What I've determined so far is that:

  • If you use .NET Core tools preview 2 (e.g., VS2015 Update 3), then everything works fine on both .NET Framework 4.5.1 and 4.6.1.
  • If you use .NET Core tools preview 3 (e.g., VS2017RC), then it works fine on .NET Framework 4.5.1, but fails with the error you posted on .NET Framework 4.6.1.
  • The issue isn't specific to NodeServices. You can repro the same error just by trying to use System.Net.Http.HttpClient (and NodeServices triggers it precisely because it uses HttpClient internally).

My guess is that the underlying cause is something similar to (if not the same as) https://github.com/aspnet/Security/issues/1046.

In the short term, one workaround is to downgrade to net451 (or switch over to .NET Core), as you can still run ASP.NET Core on that and pretty much everything should just work with that. I'll speak with the team and try to resolve the net461-specific issue.

Ahh that's my fault! Apologies I was thinking about the Templates themselves!
Sorry about that. :disappointed:

Confirmed downgrading to net451does fix the issue. I'll still holdout for a net461fix. Thanks for pushing this further!

We're also affected by this issue on VS2017 RC. It worked with VS2015.

Any updates? Thanks.

This should be fixed as of the fix to https://github.com/aspnet/Security/issues/1046#issuecomment-277200815. In other words, the problem should be gone with ASP.NET Core 1.1.1 when that is released.

Hello,
Is the issue solved?
I already have it with Axp.Net Core 1.1.1 and .Net 4.6.2 Framework

Thanks.

@SteveSanderson i have the same issue in an WPF (.netframework 4.6.2) project when using code of a .NETStandard1.4 library which uses SendAsync:

Ausnahme ausgel枚st: "System.IO.FileLoadException" in System.Net.Http.dll
Ausnahme ausgel枚st: "System.IO.FileLoadException" in System.Net.Http.dll
System.IO.FileLoadException: Die Datei oder Assembly "System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" oder eine Abh盲ngigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis 眉berein. (Ausnahme von HRESULT: 0x80131040)
Dateiname: "System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
   bei System.Net.Http.WinHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   bei System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   bei System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   bei System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   bei System.Net.Http.HttpClient.GetAsync(Uri requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   bei System.Net.Http.HttpClient.GetAsync(String requestUri)
   bei WpfApp1.MainWindow.<Button_Click>d__5.MoveNext() in C:\Users\Benni\documents\visual studio 2017\Projects\Signal-Windows\WpfApp1\MainWindow.xaml.cs:Zeile 40.

=== Zustandsinformationen vor Bindung ===
LOG: DisplayName = System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
 (Fully-specified)
LOG: Appbase = file:///C:/Users/Benni/documents/visual studio 2017/Projects/Signal-Windows/WpfApp1/bin/Debug/
LOG: Urspr眉nglicher PrivatePath = NULL
Aufruf von Assembly : System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: Diese Bindung startet im default-Load-Kontext.
LOG: Die Anwendungskonfigurationsdatei wird verwendet: C:\Users\Benni\documents\visual studio 2017\Projects\Signal-Windows\WpfApp1\bin\Debug\WpfApp1.exe.config
LOG: Die Hostkonfigurationsdatei wird verwendet: 
LOG: Die Computerkonfigurationsdatei von C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config wird verwendet.
LOG: Verweis nach der Richtlinie: System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Download von neuem URL file:///C:/Users/Benni/documents/visual studio 2017/Projects/Signal-Windows/WpfApp1/bin/Debug/System.Diagnostics.DiagnosticSource.DLL.
WRN: Der Vergleich des Assemblynamens f眉hrte zum Konflikt: Buildnummer.
ERR: Das Setup der Assembly konnte nicht abgeschlossen werden (hr = 0x80131040). Die Suche wurde beendet.

I assume it is related to this issue? Is there a workaround for this?

This appears to be an issue caused by the System.Net.Http 4.3.0 package and should be fixed in the System.Net.Http 4.3.1 package. Can you try referencing that directly?

@Tratcher Thanks! This have solved my two other issues!

the latest version of NETStandard.Library is depending on System.Net.Http 4.3.0 - will it use 4.3.1 out of the box when i add the reference?

Explicitly using 4.3.1 solves it for me too. i.e. Adding:

Hopefully new release coming with 2017 release tomorrow, so this comment may soon be irrelevent.

I just got this issue after upgrading to VS 2017 :(
Using System.Net.Http 4.3.1 solved it...
but how come just upgrade VS is causing that issue?

Sorry but where should I reference System.Net.Http 4.3.1 directly? In my web-app project that uses .NET Framework 4.6.X or in a custom build of SpaServices?

I see my previous comment had the xml suppressed. You need to add the reference to the first ItemGroup in your .csproj. Hopefully this example will appear:

  <ItemGroup>
    <!--Force new version of System.Net.Http to workaround issue in 4.3.0 with net462, should be able to remove this line soon.
    Issue is complaint of could not load file or assembly 'System.Diagnostics.DiagnosticSource' -->
    <PackageReference Include="System.Net.Http" Version="4.3.1" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
  </ItemGroup>

Thank you, @DanHarman I'll try. For the moment I've just went back to .NET 4.5.2

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sampath-Lokuge picture Sampath-Lokuge  路  4Comments

benaadams picture benaadams  路  3Comments

caesay picture caesay  路  3Comments

natemcmaster picture natemcmaster  路  4Comments

Eilon picture Eilon  路  3Comments