This repository has been archived by the owner. It is now read-only.

Application running on NET461 fails with FileLoadException #487

Closed
lruckman opened this Issue Dec 2, 2016 · 15 comments

Comments

Projects
None yet
@lruckman
Copy link

lruckman commented Dec 2, 2016

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.

@SteveSandersonMS

This comment has been minimized.

Copy link
Member

SteveSandersonMS commented Dec 5, 2016

@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) aspnet/Security#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.

@MarkPieszak

This comment has been minimized.

Copy link
Contributor

MarkPieszak commented Dec 5, 2016

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

@lruckman

This comment has been minimized.

Copy link

lruckman commented Dec 5, 2016

Confirmed downgrading to net451 does fix the issue. I'll still holdout for a net461 fix. Thanks for pushing this further!

@DanielLaberge

This comment has been minimized.

Copy link

DanielLaberge commented Dec 21, 2016

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

Any updates? Thanks.

@SteveSandersonMS

This comment has been minimized.

Copy link
Member

SteveSandersonMS commented Feb 3, 2017

This should be fixed as of the fix to aspnet/Security#1046 (comment). In other words, the problem should be gone with ASP.NET Core 1.1.1 when that is released.

@JulienM28

This comment has been minimized.

Copy link

JulienM28 commented Feb 12, 2017

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

Thanks.

@Trolldemorted

This comment has been minimized.

Copy link

Trolldemorted commented Feb 15, 2017

@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?

@Tratcher

This comment has been minimized.

Copy link
Member

Tratcher commented Feb 23, 2017

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?

@mkosieradzki

This comment has been minimized.

Copy link

mkosieradzki commented Feb 24, 2017

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

@Trolldemorted

This comment has been minimized.

Copy link

Trolldemorted commented Feb 24, 2017

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?

@DanHarman

This comment has been minimized.

Copy link
Contributor

DanHarman commented Mar 6, 2017

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.

@clement911

This comment has been minimized.

Copy link

clement911 commented Mar 8, 2017

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?

@Eshva

This comment has been minimized.

Copy link

Eshva commented Mar 15, 2017

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?

@DanHarman

This comment has been minimized.

Copy link
Contributor

DanHarman commented Mar 20, 2017

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>
@Eshva

This comment has been minimized.

Copy link

Eshva commented Mar 21, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.