New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ARM32] Could not load file or assembly 'System.ComponentModel.Primitives, Version=4.2.0.0 #9168

Closed
maartenmensink opened this Issue Jan 27, 2017 · 37 comments

Comments

Projects
None yet
@maartenmensink
Contributor

maartenmensink commented Jan 27, 2017

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
    }
  }
}

@maartenmensink maartenmensink changed the title from [ARM32] System.ComponentModel.Primitives to [ARM32] Could not load file or assembly 'System.ComponentModel.Primitives, Version=4.2.0.0 Jan 27, 2017

@gkhanna79 gkhanna79 added this to the 2.0.0 milestone Jan 30, 2017

@AlexGhiondea AlexGhiondea assigned safern and unassigned AlexGhiondea Jan 30, 2017

@AlexGhiondea

This comment has been minimized.

Member

AlexGhiondea commented Jan 30, 2017

@safern could you take a look at this?

@safern

This comment has been minimized.

Member

safern commented Jan 30, 2017

Yes will take a look at this later today @AlexGhiondea

@tomkuijsten

This comment has been minimized.

tomkuijsten commented Feb 6, 2017

Any update on this @safern ? We're facing the same issue.

@mne91

This comment has been minimized.

mne91 commented Feb 6, 2017

I have the same issue...

@safern

This comment has been minimized.

Member

safern commented Feb 6, 2017

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.

@mne1991

This comment has been minimized.

mne1991 commented Feb 6, 2017

@safern , that workaround didn't work for me unfortunatelly, I get error in project.lock.json and the VS reverts it to its original situation.
Could you expect the estimated time when will the real solution come?

@safern

This comment has been minimized.

Member

safern commented Feb 6, 2017

@mne1991 what is the error you are getting in project.lock.json? Could you please provide me with your project.json to see if I can unblock you?

@mne1991

This comment has been minimized.

mne1991 commented Feb 6, 2017

@safern Thank you for trying to help, actually what I am trying to is deploying the very basic template website, which visual studio 2015 generates when you create an ASP.Net Core Web Application. I just create that and try to public it to my RaspberyPi3, after publishing I copy everything published to my RPi3 (I tried to not change anything except the version in the file WebApplication1.runtime... to fit the .net core version), but I get the same error as mention in this issue. Could you try generting that? because the .json files are very long. Would take a look if you are able to get it running on RPi? thank you in advance!

@joperezr

This comment has been minimized.

Member

joperezr commented Feb 6, 2017

I am trying to is deploying the very basic template

@mne1991 depending on the specific version of VS that you are using the templates might be different, so it would really help diagnosing your issue if you can provide the project.json (not the project.lock.json which is the very long one) and ideally the version of the CLI you are using which you can get by typing dotnet --version on the command line. The error mentioned in this issue is caused by the additional dependencies that @maartenmensink has which are pulling in older versions of assemblies, so by looking at your project.json we could determine what is the right workaround for you.

@mne1991

This comment has been minimized.

mne1991 commented Feb 6, 2017

Bellow is my project.json file, and here is my .net version:

root@dotnet:/dotnet# ./dotnet --version

Microsoft .NET Core Shared Framework Host

  Version  : 1.2.0-beta-001291-00
  Build    : 04c0d542e93425601b68d44c9b1fa4b6df37b050

project.json:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "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%" ]
  }
}
@safern

This comment has been minimized.

Member

safern commented Feb 6, 2017

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!

@mne1991

This comment has been minimized.

mne1991 commented Feb 6, 2017

@safern Thank you for that and I really appreciate your help.

I tried just to paste what you gave me in my project.json and then published the project and copied it to my RPi3, and then tried to start, but I get version error, therefore I edited my WebApplication.runtime.json file to fit my .net core version and then retried, and I get other exceptions:

So here is the summery of what I have done:

root@dotnet:/dotnet/PublishOutput# ../dotnet WebApplication1.dll
The specified framework 'Microsoft.NETCore.App', version '1.0.1' was not found.
  - Check application dependencies and target a framework version installed at:
      /dotnet/shared/Microsoft.NETCore.App/
  - The following versions are installed:
      1.2.0-beta-001291-00
  - Alternatively, install the framework version '1.0.1'.
root@dotnet:/dotnet/PublishOutput# vim WebApplication1.runtimeconfig.json
root@dotnet:/dotnet/PublishOutput# ../dotnet WebApplication1.dll

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Extensions.DependencyInjection.ServiceProvider' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Threading, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at System.Dynamic.Utils.CacheDict`2.TryGetValue(TKey key, TValue& value)
   at System.Dynamic.Utils.TypeExtensions.GetParametersCached(MethodBase method)
   at System.Linq.Expressions.Expression.ValidateMethodAndGetParameters(Expression instance, MethodInfo method)
   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0)
   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression[] arguments)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at WebApplication1.Program.Main(String[] args)
Aborted (core dumped)
root@dotnet:/dotnet/PublishOutput#

@tomkuijsten

This comment has been minimized.

tomkuijsten commented Feb 7, 2017

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

@mne1991

This comment has been minimized.

mne1991 commented Feb 7, 2017

@safern @tomkuijsten Thank you very much for you!!! I got it working! I added this as well:

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

Just for the other people, don't forget that the default behaviour is to listen only on localhost, at first I couldn't view the page over my LAN and I thought it didn't work, but that was not the case, it works perfectly!!! thank you again for your help.

@maartenmensink

This comment has been minimized.

Contributor

maartenmensink commented Feb 7, 2017

@safern Thanks for the update and help.

I updated my project.json based on your info. The application is running for most parts but most important i am able to perform api request to the webserver on the RPi3.

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

  "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%" ]
  }
}

@tomkuijsten

This comment has been minimized.

tomkuijsten commented Feb 7, 2017

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

@TAGC

This comment has been minimized.

TAGC commented Feb 7, 2017

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.

@joperezr

This comment has been minimized.

Member

joperezr commented Feb 7, 2017

Great to know that this issue was sorted out. Special thanks to @safern @maartenmensink @tomkuijsten and @mne1991. I'll close this issue for now, since the new approach that we are working on is having one flat package that contains the right set of dependencies to avoid this sort of problems.

@joperezr joperezr closed this Feb 7, 2017

@safern

This comment has been minimized.

Member

safern commented Feb 7, 2017

Great that we could help and unblock you guys! Thanks for helping us sort out the issue with your feedback and tips!! Great to see that your .NET Core apps are working now.

Thanks @maartenmensink for opening the issue and @tomkuijsten @mne1991 @TAGC for complementing the issue on how to get the web apps running and working!

Thanks @joperezr for helping out!

@tomkuijsten

This comment has been minimized.

tomkuijsten commented Feb 7, 2017

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!

@mne1991

This comment has been minimized.

mne1991 commented Feb 7, 2017

@tomkuijsten Not only for Windows, but also for Linux ;) thanks for you all.

@tomkuijsten

This comment has been minimized.

tomkuijsten commented Feb 8, 2017

True :) I put all the configuration steps together in a blog post to explain each step.

@mne1991

This comment has been minimized.

mne1991 commented Feb 10, 2017

@safern May I ask how you were able to know the version you had to use? for example here:

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

the error message has this version 4.2.0.0, how did you know that you needed to enter 4.3.0?

@safern

This comment has been minimized.

Member

safern commented Feb 10, 2017

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

@mne1991

This comment has been minimized.

mne1991 commented Feb 10, 2017

@safern Thank you! So what I understand is: The version my application is using is 4.2.0.0, but when I move the app to another platform (RPi3), the CLR on RPi expects another version 4.3.0 (a newer one because this CLR on RPi is newer and is still beta and uses newer beta packages). therefore he doesn't use the packages available in my app, or did I misunderstand anything?

@safern

This comment has been minimized.

Member

safern commented Feb 10, 2017

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

@mne1991

This comment has been minimized.

mne1991 commented Feb 10, 2017

@safern. That is clear now! thanks! Just what is still unclear to me is:

exclude": "runtime" closure when bringing that dependency, to say - ignore the runtime assembly, use the one that my application needs.

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?

@safern

This comment has been minimized.

Member

safern commented Feb 10, 2017

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

@mne1991

This comment has been minimized.

mne1991 commented Feb 10, 2017

@safern Thank you very much!

@PArpad

This comment has been minimized.

PArpad commented Feb 11, 2017

Hello!
I'm relatively new to ASP.NET, and .NET core, so sorry if my question will be a bit silly.
I've followed the steps, and i could run a console app. without any trouble on my RPI, but i got the exception which this thread is about when i've tried it with a web application.
I wanted to follow your solution, but i couldn't make it work.
My problem is that i am using VS 2017RC, and if my research is right, they've removed project.json in this version, and the replacement would be project.csproj. I've tried to modify it to fit this solution, but i still get the same exception.

In the VS2017RC i've started a new web application project, and only modified the project.csproj to 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="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" />
    <PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" Exclude="runtime" />
    <PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0" Exclude="runtime" />
    <PackageReference Include="System.Collections.Specialized" Version="4.3.0" Exclude="runtime" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
  </ItemGroup>

</Project>

The exception:

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 teszt01.Program.Main(String[] args) in d:\Users\Arpi\Documents\Visual Studio 2017\Projects\teszt01\teszt01\Program.cs:line 14
Aborted

Can you please point me out to the right direction?

@mne1991

This comment has been minimized.

mne1991 commented Feb 11, 2017

@PArpad , please paste your project.json file. I will edit it to you to get it work.

@PArpad

This comment has been minimized.

PArpad commented Feb 11, 2017

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

@safern

This comment has been minimized.

Member

safern commented Feb 11, 2017

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

This comment has been minimized.

mne1991 commented Feb 11, 2017

@PArpad Sorry, I didn't know that it is different, waiting for your feed back. Thanks for @safern who always saves us :D

@safern Could you explain in some words which phrase is exactly the alternative of exclude runtime?

@PArpad

This comment has been minimized.

PArpad commented Feb 12, 2017

@safern Thank you, it worked like a charm. Looking at what you modified, i was on a good path, just didn't mix the previous solution and the .csproj properly.
I still got some exceptions but those are pathing issues.

@DaEkstrim

This comment has been minimized.

DaEkstrim commented Feb 12, 2017

I do not wish to barge into the conversation, but I have been following and trying out the solutions outlined in here, and the app works fine on RPI. However when I attempt to debug it in Visual Studio 2015, I'm getting an error stating

An exception of type 'System.IO.FileNotFoundException' occurred in
 System.Private.CoreLib.ni.dll but was not handled in user code

Additional information: Could not load file or assembly 'System.ComponentModel.TypeConverter,
 Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Why is it that even though we're specifically telling dotnet to ignore runtime version, it is checking for a specific version?

@shielsingh

This comment has been minimized.

shielsingh commented Apr 14, 2017

Hi All,

I followed the steps as mentioned but I am not able to access the Web API from outside. Please help me to unblock this.

The details of my environment are as follows

Microsoft Visual Studio Community 2017
Version 15.0.26228.10 D15RTWSVC
Microsoft .NET Framework
Version 4.6.01586

Added hosting.json with following contents and also added firewall exception for the port.

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

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