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

.NET Core Web API on ARM? #3

Closed
challe opened this Issue Feb 26, 2017 · 22 comments

Comments

Projects
None yet
4 participants
@challe
Copy link

challe commented Feb 26, 2017

Is there a way to start a web API using Kestrel with the Ubuntu build of Core?

@stevedesmond-ca

This comment has been minimized.

Copy link
Owner

stevedesmond-ca commented Feb 26, 2017

@challe

This comment has been minimized.

Copy link

challe commented Feb 26, 2017

I'm currently in the process of doing just that. I have dotnet core 2.0.0-alpha-004853 on my windows machine.
I created a basic project using dotnet new webapi, changed the Property Group in my project.csproj file to:

<PropertyGroup>
  <TargetFramework>netcoreapp2.0</TargetFramework>
  <RuntimeIdentifiers>ubuntu.16.04-arm</RuntimeIdentifiers>
</PropertyGroup>

After that I simply did a dotnet restore followed by dotnet publish --runtime ubuntu.16.04-arm
After transfering the files to my raspberry pi 3, the first thing I did was to change my test.runtimeconfig.json so that it now contains:

{
  "runtimeOptions": {
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "2.0.0-beta-001518-00"
    },
    "configProperties": {
      "System.GC.Server": true
    }
  }
}

When doing /usr/bin/dotnet /home/challe/dev/test/test.dll I get Could not load file or assembly 'System.ComponentModel.Primitives, Version=4.2.0.0.

Edit: Ok, so according to dotnet/coreclr#9168 (comment), that error can be fixed by adding a few lines to your project.csproj. This is now my full project.csproj:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>ubuntu.16.04-arm</RuntimeIdentifiers>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <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.AspNetCore" Version="1.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
  </ItemGroup>

</Project>

When I try to run the DLL now, I get Could not load file or assembly 'System.ComponentModel, Version=4.0.3.0' I tried adding it as a PackageReference, the same way as the other ones above. Then I get another error about it not being able to load file or assembly System.Threading.

Should I keep adding package references like this or am I doing something fundamentally wrong here?

@stevedesmond-ca

This comment has been minimized.

Copy link
Owner

stevedesmond-ca commented Feb 26, 2017

@challe

This comment has been minimized.

Copy link

challe commented Feb 26, 2017

Thanks, I didnt know that! However, I'm still having problems with it not being able to load certain DLLs. I asked about my current problem in that other issue.

@stevedesmond-ca

This comment has been minimized.

Copy link
Owner

stevedesmond-ca commented Feb 26, 2017

@stevedesmond-ca

This comment has been minimized.

Copy link
Owner

stevedesmond-ca commented Feb 26, 2017

@challe

This comment has been minimized.

Copy link

challe commented Feb 26, 2017

Thanks for taking the time to help me out. Ok - so here is what I'm doing now.

dotnet --version
2.0.0-alpha-004853

cd c:\dev\test
dotnet new webapi

I then update the test.csproj file, so that it looks like this. Basically, I add ubuntu to RuntimeIdentifiers and my RuntimeFrameworkVersion. Also, I add the PackageReference-tags in ItemGroup, to bypass my initial problem as mentioned here:


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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>ubuntu.16.04-arm</RuntimeIdentifiers>
    <RuntimeFrameworkVersion>2.0.0-beta-001509-00</RuntimeFrameworkVersion>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <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.AspNetCore" Version="1.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
  </ItemGroup>

</Project>

dotnet restore

dotnet run
C:\Program Files\dotnet\sdk\2.0.0-alpha-004853\Microsoft.Common.CurrentVersion.targets(1951,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [c:\dev\test\test.csproj]
Hosting environment: Production
Content root path: c:\dev\test
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

I can go to http://localhost:5000/api/values and there I see the expected JSON.
Then I do

dotnet publish --runtime ubuntu.16.04-arm

Here, I'm not sure if I should copy all of the files produced in netcoreapp2.0, or just the files inside netcoreapp2.0/ubuntu.16.04-arm/publish to the raspberry pi. There is a test.dll in both of those roots. I have tried both, resulting in different errors.

Before I try running, I change the test.runtimeconfig.json to

{
  "runtimeOptions": {
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "2.0.0-beta-001518-00"
    },
    "configProperties": {
      "System.GC.Server": true
    }
  }
}

and then try /usr/bin/dotnet /home/challe/dev/original/test.dll

This now results in

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0

Do you see any obvious problems with what I'm doing or should I create a separate issue in https://github.com/dotnet/coreclr?

@stevedesmond-ca

This comment has been minimized.

Copy link
Owner

stevedesmond-ca commented Feb 26, 2017

@challe

This comment has been minimized.

Copy link

challe commented Feb 27, 2017

Ok - thanks. I'll look into it. The template is probably not updated then, since I did dotnet new webapi using the 2.0 framework.

@challe

This comment has been minimized.

Copy link

challe commented Feb 27, 2017

I didnt mean for you to be my personal technical support, so if you don't have time - I understand.
Just let me know and I'll ask in the official project.

I can't seem to find a 2.x version of these packages:
https://dotnet.myget.org/feed/aspnetcore-release/package/nuget/Microsoft.AspNetCore
https://dotnet.myget.org/feed/aspnetcore-release/package/nuget/Microsoft.AspNetCore.Mvc

Do you know if those exist? Where can I find them?

@stevedesmond-ca

This comment has been minimized.

Copy link
Owner

stevedesmond-ca commented Feb 27, 2017

@challe

This comment has been minimized.

Copy link

challe commented Feb 27, 2017

Thank you for all your help. You can close this issue now if you want to.

I'm writing down all of my steps to making this work so hopefully I can write some sort of wiki about this in the next couple of days.

@vallgrenerik

This comment has been minimized.

Copy link

vallgrenerik commented Mar 3, 2017

@challe Have you had the time to write the wiki? I would love to read it as will try to do the same on my Raspberry.

@challe

This comment has been minimized.

Copy link

challe commented Mar 3, 2017

@vallgrenerik Nice! I am in the process of writing it. However, I'm still having issues with getting it working, so I'm kind of stuck at the last step of running the actual API on the Raspberry Pi. I asked about my problems over at the cli repo and they asked me to create an issue. So I would recommend following the discussion here: dotnet/cli#5868

@vallgrenerik

This comment has been minimized.

Copy link

vallgrenerik commented Mar 3, 2017

@challe
Awesome, thanks. I will follow that thread as well. When you're done with the wiki, please notify me :)

@challe

This comment has been minimized.

Copy link

challe commented Mar 3, 2017

@vallgrenerik I have one published here now. Still not working but atleast you get an overview of what needs to be done to hopefully get it to work in the future. Just ask if anything is unclear.

@vallgrenerik

This comment has been minimized.

Copy link

vallgrenerik commented Mar 3, 2017

@challe Thank you so much! I will read it when I have the time :) Will you update the wiki if you solve your current problems?
What OS are you running on your Rpi? Ubuntu I guess? What version?

@challe

This comment has been minimized.

Copy link

challe commented Mar 3, 2017

@vallgrenerik It's all in the wiki :). Ubuntu 16.04. And yes, I will continue to update it the further I get.

@timdows

This comment has been minimized.

Copy link

timdows commented Mar 5, 2017

@challe, today I tried to reproduce your issue on a Raspberry Pi 3 (Ubuntu MATE 16.04.2 LTS).
Environment:

  • Raspberry Pi 3
  • 16GB SanDisk microSDHC (Class 10)
  • Ubuntu MATE 16.04.2 LTS (Linux hostname 4.4.38-v7+ #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l armv7l armv7l GNU/Linux)
  • .NET Core on the Raspberry Pi
    • Version: 2.0.0-beta-001663-00
    • Build: da54fbb7911c7ed584bfff54cdf223617959df6c
  • .NET Core on my Windows machine
    • Version: 2.0.0-alpha-005165
    • Commit SHA-1 hash: 4a0724e136

Created a new webapi project
dotnet new webapi

Changed the .csproj file


  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
	<RuntimeIdentifiers>ubuntu.16.04-arm</RuntimeIdentifiers>
    <RuntimeFrameworkVersion>2.0.0-beta-001663-00</RuntimeFrameworkVersion>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
  </ItemGroup>

</Project>

After running it without any issues on the Windows environment I published it and transferred the output to the Pi.
dotnet publish -r ubuntu.16.04-arm

On the Raspberry Pi 3 it runs without any issues. I didn't get any Kestrell issues like you described. So I wrote a quick blog about the steps I took:
https://timdows.com/projects/asp-net-core-2-0-0-beta-on-a-raspberry-pi-3/

@challe

This comment has been minimized.

Copy link

challe commented Mar 5, 2017

This is really strange. I just went back to using my own old csproj-file that I posted in another comment in this very issue. It all works fine now. The only thing that differs now from back then is that I currently also use the 2.0.0-beta-001663-00 version of the runtime on my Raspberry Pi instead of the 2.0.0-beta-001509-00 as I did back then.

After Steve told me that the packages are 1.x compatible and that I needed to use 2.x compatible ones, I never went back to try this approach again.

Thanks for letting me know. I have been fighting this thing for many hours now...

@stevedesmond-ca

This comment has been minimized.

Copy link
Owner

stevedesmond-ca commented Mar 5, 2017

@challe

This comment has been minimized.

Copy link

challe commented Mar 5, 2017

Yes, ofcourse. And I have actually filed several tickets regarding problems I found using the 2.x compatible packages. So the time is not all wasted. :)

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