runtime: [ARM32] Could not load file or assembly 'System.ComponentModel.Primitives, Version=4.2.0.0
I have a project that i am trying to get working on the RPi3 Ubuntu. I installed the latest and greatest based on https://github.com/dotnet/core/blob/master/samples/RaspberryPiInstructions.md
I am able to run the samples from https://github.com/dotnet/core/tree/master/samples without any issue but when i try to start our project i get the following stack trace
Stack Trace
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.ComponentModel.Primitives, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider.CreateFileWatcher(String root)
at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String applicationName, String contentRootPath, WebHostOptions options)
at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Machine.Manager.Program.Main(String[] args)
Aborted (core dumped)
Enviroment Ubuntu 16.04 on Raspberry PI 3 runtime version : 1.2.0-beta-001291-00
project.json
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Machine": "1.0.0-*",
"Machine.Core": "1.0.0-*"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dnxcore50",
"dotnet5.6",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"System.ComponentModel": "4.3.0",
"System.ComponentModel.Primitives": "4.3.0",
"System.Threading": "4.3.0"
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Project.runtimeconfig.json
{
"runtimeOptions": {
"framework": {
"name": "Microsoft.NETCore.App",
"version": "1.2.0-beta-001291-00"
},
"configProperties": {
"System.GC.Server": true
}
}
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 37 (13 by maintainers)
Any update on this @safern ? We’re facing the same issue.
Hi @PArpad, the problem is the same but you have to exclude the Runtime assets on the
.csproj
file for some assemblies which are explained earlier as being causing this error. To fix this we have to do the equivalent in the.csproj
as adding the"exclude": "runtime"
in this dependencies in theproject.json
. To solve this please add to yourproject.csproj
the following dependencies above<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
:And delete the
PackageReference
items where you added theexclude=runtime
since this are the same dependencies you will be adding here.So your
project.csproj
will look like this:True 😃 I put all the configuration steps together in a blog post to explain each step.
@mne1991 the steps you should follow to make it available from the outside:
Add a file named
hosting.json
to your project and edit:Make sure the file is copied when publishing by adding it to the publishOptions in your
project.json
file:Edit your main method in the
Project.cs
file and make it look like this:And finally, you should add a firewall rule to allow traffic through your post by entering in a powershell terminal:
Now use fiddler or any other tool to reach your api at
http://yourserver:5102/api/values
.@PArpad Sorry, I didn’t know that it is different, waiting for your feed back. Thanks for @safern who always saves us 😄
@safern Could you explain in some words which phrase is exactly the alternative of exclude runtime?
@mne1991 , My problem is that i don’t have one, while working in VS2017. And according to the link below, i shouldn’t have one, since it has been removed and replaced by the editable .csproj file. This is the reason i’m a bit lost, and looking for clarification. https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-tools-msbuild-alpha/
Mainly yes. What
"exclude": "runtime"
does is:So basically it will exclude the assembly that your dotnet cli uses for runtime – this will be the dotnet cli that you used to published your app not the one you are using in your RPi to run it.
This being said, when running it will see it has a dependency on
System.ComponentModel.Primitives
but it will not have any assembly in the project, so then it will use the CLR assembly. In this case when you were publishing your app before updating theproject.json
it was trying to use the assembly published with your application which was a different version from the CLR expected assembly. So to avoid that, when publishing we just tell the framework to ignore the Runtime sections of that target.That made more clear? @mne1991
No, the assembly is what your application is using. The package is what contains the assembly of the dependency you are referencing. So when you say on your
project.json
:You’re telling the dotnet cli that you depend on that package version (4.3.0) which will contain point to an assembly
System.ComponentModel.Primitives.dll
that can be any version number. In this case for the CLR which is 4.2.0.0. Your application is actually using 4.1.1.0 as I remember, and that is the assembly that the package 4.3.0 (which you application is saying it depends on it) points to.In this case since the runtime is on a beta and uses newer APIs from that assembly is using a 4.2.0.0 assembly version which is on a beta package that has not being released. So that is why we added the
"exclude": "runtime"
closure when bringing that dependency, to say - ignore the runtime assembly, use the one that my application needs.Makes sense? @mne1991
Yes @mne1991 so the 4.2.0.0 is the assembly version that the runtime and/or your project is using, but the version in the
project.json
is the package version from NuGet, and that package contains the assembly inside of it, so if the NuGet package version is 1.2 that doesn’t necessarily means that the assembly version will be 1.2To know what version to include in the
project.json
you can go to NuGet and search for the dependency, so in this case I searched forSystem.ComponentModel.Primitives
and got this result https://www.nuget.org/packages/System.ComponentModel.Primitives/ and as you can see that the latest released package 4.3.0Was waiting for this moment since the announcement of Win10IoT for the Pi, big thanks to all the people at Microsoft and especially @safern for the initial investigation!
Excellent work guys! 👍
Between these modifications and this I’ve managed to get an ASP.NET Core web application running on my RPi that can communicate with a Cortex-M3 microcontroller device over USB. This is something I’ve been hoping to achieve for several months and it’s exciting to finally have something working.
Got it running on a Pi2, additionally to what @safern explained (big thanks!), you should also add:
And copy the netstandard1.7 version of
System.Threading.dll
(4.1.0.0 version).The result:
The only teeny tiny problem is that I can’t get any response from it yet 😃
Hey @mne1991 so I was able to run the sample app with your
project.json
in Rpi. Thanks for providing me with this information, the dotnet version you provided is the one in your Rpi right?So your project json should look like this:
Hope this unblocks you!
Here is my update from what I was able to investigate after getting a repro.
The .NET Core Runtime for Ubuntu on ARM is a community developed project which is currently in beta and it uses some assemblies that aren’t released yet, they are still in beta, such as:
System.ComponentModel.Primitives
which is the error that @maartenmensink is pointing out.The error here is that the released .NET Core SDKs (1.1 or 1.0) are using the latest released assemblies which in
System.ComponentModel.Primitives
is 4.1.1.0 so when we publish our portable app it will drop that assembly version. When trying to run this app in the .NET Core Runtime for Ubuntu on ARM, the runtime is expecting this assembly version to be 4.2.0.0, so that is why you are getting that error. It happens with other assemblies such asSystem.Collections.Specialized
orSystem.ComponentModel.TypeConverter
. In the meantime while we ship our new SDKs or the guys working on getting a full .NET Core SDK for Ubuntu on ARM to be able to directly publish the app on the Raspberry Pi and use the runtime expected assemblies, I have one solution.We have a way to tell the runtime and cli to exclude the runtime assembly specific on execution from the
project.json
which is the following:So if we do this for the assemblies that are causing the error it would be fix.
So an example of the
project.json
with the dependencies @maartenmensink posted on this issue to make it work would be:We are working on driving this kind of issues to always use the latest version of the assembly but as of now that would be the workaround. So if you need to bring more dependencies to your project and you get that exception for that specific assembly or an assembly that is brought because other dependency depends on it (In this case it happened that with
System.Collections.Specialized
whichSystem.ComponentModel.TypeConverter
depends on that assembly and when trying to run it I would get the same error but forSystem.Collections.Specialized
.Sorry for the late update I was investigating and trying to find the best solution for you guys.