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)

Most upvoted comments

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 the project.json. To solve this please add to your project.csproj the following dependencies above <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />:

<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0">
   <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
</PackageReference>
<PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0">
   <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Collections.Specialized" Version="4.3.0">
    <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Linq" Version="4.3.0">
    <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
</PackageReference>

And delete the PackageReference items where you added the exclude=runtime since this are the same dependencies you will be adding here.

So your project.csproj will look like this:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0">
     <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
   </PackageReference>
   <PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0">
      <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Collections.Specialized" Version="4.3.0">
      <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Linq" Version="4.3.0">
      <IncludeAssets>Analyzers;Build;Compile;ContentFiles;Native</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.1" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
  </ItemGroup>

</Project>

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:

{
  "server.urls": "http://*:5102"
}

Make sure the file is copied when publishing by adding it to the publishOptions in your project.json file:

"publishOptions": {
  "include": [
    "wwwroot",
    "**/*.cshtml",
    "appsettings.json",
    "hosting.json",
    "web.config"
  ]
},

Edit your main method in the Project.cs file and make it look like this:

var config = new ConfigurationBuilder()
  .SetBasePath(Directory.GetCurrentDirectory())
  .AddJsonFile("hosting.json", optional: true, reloadOnChange: true)
  .Build();

var host = new WebHostBuilder()
  .UseConfiguration(config)
  .UseKestrel()
  .UseContentRoot(Directory.GetCurrentDirectory())
  .UseIISIntegration()
  .UseStartup<Startup>()
  .Build();

host.Run();

And finally, you should add a firewall rule to allow traffic through your post by entering in a powershell terminal:

netsh advfirewall firewall add rule name="Open Port 5102" dir=in action=allow protocol=TCP localport=5102

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/

So that means I can either use what the CLR uses, or I can just ignore what the CLR has and use what I included in my application by using "exclude": "runtime", right?

Mainly yes. What "exclude": "runtime" does is:

Exclude the Runtime, Resources, and FrameworkAssemblies sections of the target.

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 the project.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:

"System.ComponentModel.Primitives": {
          "version": "4.3.0",
          "exclude": "runtime"
},

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.2

To 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 for System.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.0

Was 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:

"System.Linq": {
      "version": "4.3.0",
      "exclude": "runtime"
    }

And copy the netstandard1.7 version of System.Threading.dll (4.1.0.0 version).

The result:

capture

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:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "System.ComponentModel.TypeConverter": {
      "version": "4.3.0",
      "exclude": "runtime"
    },
    "System.ComponentModel.Primitives": {
      "version": "4.3.0",
      "exclude": "runtime"
    },
    "System.Collections.Specialized": {
      "version": "4.3.0",
      "exclude": "runtime"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "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",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

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 as System.Collections.Specialized or System.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:

"Assembly": {
     "version": "version-number",
     "exclude": "runtime"
}

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:

{
  "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.TypeConverter": {
          "version": "4.3.0",
          "exclude": "runtime"
        },
        "System.ComponentModel.Primitives": {
          "version": "4.3.0",
          "exclude": "runtime"
        },
        "System.Collections.Specialized": {
          "version": "4.3.0",
          "exclude": "runtime"
        },
        "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%" ]
  }
}

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 which System.ComponentModel.TypeConverter depends on that assembly and when trying to run it I would get the same error but for System.Collections.Specialized.

Sorry for the late update I was investigating and trying to find the best solution for you guys.