Hi All,
I have an issue with hosting a self-contained ASP.NET Core web application on Raspberry Pi. When I try to run the application I get this error:
Unhandled exception. System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.ApplicationParts.ConsolidatedAssemblyApplicationPartFactory' from assembly 'Microsoft.AspNetCore.Mvc.Razor, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at System.Reflection.RuntimeAssembly.GetTypeCore(String, ReadOnlySpan`1, Boolean, Boolean)
at System.Reflection.TypeNameParser.GetType(String, ReadOnlySpan`1, String)
at System.Reflection.TypeNameParser.NamespaceTypeName.ResolveType(TypeNameParser&, String)
at System.Reflection.TypeNameParser.Parse()
at System.Reflection.TypeNameParser.GetType(String, Func`2, Func`4, Assembly, Boolean , Boolean , Boolean )
at System.Reflection.TypeNameParser.GetType(String, Assembly, Boolean , Boolean )
at System.Type.GetType(String, Boolean)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute.GetFactoryType()
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartFactory.GetApplicationPartFactory(Assembly)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateDefaultParts(String)
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection, IWebHostEnvironment)
at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection)
at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddRazorPagesCore(IServiceCollection)
at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddRazorPages(IServiceCollection)
at Program.$(String[]) in C:\Users\mihas\source\repos\HelloWorld\Program.cs:line 4
Aborted
In my application on line 4 there is a code:
// Add services to the container.
builder.Services.AddRazorPages();
I don't understand. If the application is self-contained it should work regardless of the runtime being installed or not on the device which is going to run the application. Does someone know what I'm missing?
Jayraj ChhayaPosted Sep 3, 2024, 7:56 AM
The error you are experiencing typically arises from a mismatch between the ASP.NET Core version used during development and the runtime environment on the Raspberry Pi. Even though your application is self-contained, it still requires all dependencies to be compatible with the target architecture.
Here are a few steps to troubleshoot and resolve the issue:
Check Target Framework: Ensure that your project is targeting a compatible version of .NET Core that is supported on Raspberry Pi. For example, if you are using .NET 8, verify that it is installed correctly.
Rebuild the Application: Sometimes, rebuilding the application can resolve issues related to cached assemblies. Use the command:
Verify Dependencies: Ensure that all NuGet packages are compatible with the target framework. You can check the versions in your
.csprojfile.Run on the Correct Architecture: Make sure you are running the application on a Raspberry Pi with the correct architecture (e.g., ARM).
Check for Missing Assemblies: If the error persists, check if the
Microsoft.AspNetCore.Mvc.Razorassembly is included in the published output. You can do this by inspecting thebin/Release/net8.0/linux-arm/publishdirectory.By following these steps, you should be able to resolve the issue and successfully host your ASP.NET Core application on Raspberry Pi.