Tom Warner
Tom Warner

Reputation: 3598

Could not load file or assembly 'Microsoft.AspNetCore.SpaProxy'?

I have a .NET 8 app that is using (well, attempting to use) the NetCore SpaProxy library to set up an SPA. I have referenced the latest version (9.0.0-rc.1.24452.1) of Microsoft.AspNetCore.SpaProxy in the .csproj:

<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="9.0.0-rc.1.24452.1" />

I have restored, updated, cleaned etc all projects several times. I have confirmed that ASPNETCORE_HOSTINGSTARTUPASSEMBLIES: Microsoft.AspNetCore.SpaProxy is set as an environment variable. Every time I try to run the application (through my IDE (Rider) or through dotnet run in the CLI) I get the following error:

Hosting startup assembly exception

System.InvalidOperationException: Startup assembly Microsoft.AspNetCore.SpaProxy failed to execute. See the inner exception for more details.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.SpaProxy, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'Microsoft.AspNetCore.SpaProxy, Culture=neutral, PublicKeyToken=null'

at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.ExecuteHostingStartups()

This prevents the SPA from loading. I understand that the application is failing to find the DLL on startup, however, nothing I tried has fixed this. I have confirmed the DLL exists on disk in exactly the default folder where NuGet installed it. I have manually copied the DLL file to the output directory. I have attempted loading it directly through calls to Assembly.Load in the opening lines of program.cs. If I could somehow, metaphorically or literally, wave this DLL directly in the face of the .NET runtime as the program starts up, I would be doing that.

Is there any way (ideally good, but I'll take anything) to get .NET to load this assembly on startup so that it can then find it when it needs it?

BEFORE YOU CLOSE THIS QUESTION AS A DUPLICATE:

I'm aware there is a very similar question where someone was able to fix this by updating the package version. I have updated package versions until my eyeballs bleed. Every single reference in this project is updated to the latest possible version. It is not that.

Upvotes: 1

Views: 361

Answers (1)

Guru Stron
Guru Stron

Reputation: 142903

rc.1.24452.1 is a release candidate version, i.e. preview one (for .NET 9), so probably it is better to downgrade to 8.* (8.0.8 ATM) since you are targeting .NET 8 (when managing/updating packages disable the preview versions and use the latest "stable" ones).

Upvotes: 1

Related Questions