问题
I am following various blog posts showing how to take an ASP.NET Core 1.0 application (formerly ASP.NET 5) and then install the correct .net core runtimes for Linux, so you can run on Linux, specifically on ubuntu 14.04 lts.
I have the .net core tools (dnvm and dnx) installed, and I have an ASP.NET application that is just the standard template application, and I have created a repository containing it, and am trying to run it on my Ubuntu system. The latest .Net and Visual Studio tooling on Windows is 1.0.0-beta8, and I have that also on my ubuntu box, which reports that Mono-x64-1.0.0-beta8-15858 is intalled.
I cloned my source code onto the ubuntu system and ran dnu restore, which succeeded.
From the folder containing project.json, I run dnx web
and I get this:
Application startup exception: System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.Marshal' from assembly 'System.Reflection.Metadata'.
at System.Reflection.Internal.StreamMemoryBlockProvider.ReadMemoryBlockNoLock (System.IO.Stream stream, Boolean isFileStream, Int64 start, Int32 size) [0x00000] in <filename unknown>:0
at System.Reflection.PortableExecutable.PEReader..ctor (System.IO.Stream peStream, PEStreamOptions options, Nullable`1 sizeOpt) [0x00000] in <filename unknown>:0
at System.Reflection.PortableExecutable.PEReader..ctor (System.IO.Stream peStream, PEStreamOptions options) [0x00000] in <filename unknown>:0
at Microsoft.CodeAnalysis.ModuleMetadata.CreateFromStream (System.IO.Stream peStream, PEStreamOptions options) [0x00000] in <filename unknown>:0
at Microsoft.Dnx.Compilation.CSharp.MetadataReferenceExtensions.CreateAssemblyMetadata (IMetadataFileReference fileReference) [0x00000] in <filename unknown>:0
at Microsoft.Dnx.Compilation.CSharp.RoslynCompiler+<>c__DisplayClass8_0.<.ctor>b__1 (Microsoft.Dnx.Compilation.Caching.CacheContext ctx) [0x00000] in <filename unknown>:0
at Microsoft.Dnx.Compilation.Caching.CacheExtensions+<>c__DisplayClass0_0`1[Microsoft.CodeAnalysis.AssemblyMetadata].<Get>b__0 (Microsoft.Dnx.Compilation.Caching.CacheContext ctx) [0x00000] in <filename unknown>:0
at Microsoft.Dnx.Compilation.Caching.Cache.CreateEntry (System.Object k, System.Func`2 acquire) [0x00000] in <filename unknown>:0
at Microsoft.Dnx.Compilation.Caching.Cache+<>c__DisplayClass5_0.<AddEntry>b__0 () [0x00000] in <filename unknown>:0
at System.Lazy`1[Microsoft.Dnx.Compilation.Caching.Cache+CacheEntry].InitValue () [0x00000] in <filename unknown>:0
Is this indicating that there are conflicting versions of components or something is missing in my .dnx folder or that there is something wrong in my project source code?
At first I saw another weird exception, which I think had something to do with an "1.0.0-rc2" build of dnvm that was briefly visible on public servers today, then disappeared.
Some general setup steps:
- Inspect ~/.config/NuGet/NuGet.Config, it should be like this:
.
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetbeta8/api/v2/" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<disabledPackageSources />
</configuration>
Make sure dnx and dnu and dnvm binaries are present and up to date. Make sure libuv exists and is the correct version. Install runtimes if they are not present. (Check them with dnvm list, use dnvm install to install.)
Clone your sources.
Select a dnx version via dnvm use.
Make sure your user-account-level dnx runtime packages are restored via dnu restore.
??What??
Go to folder containing project.json and run
dnx web
. Success?
Update: If I use dnvm use 1.0.0-beta8 on ubuntu 14.04, the dnx web runtime fault may be Missing method AllocHGlobal in assembly /home/user/.dnx/runtimes/dnx-mono.1.0.0-beta8/bin/System.Reflection.Metadata.dll, type System.Runtime.InteropServices.Marshal
or it may be the System.Runtime.InteropServices.Marshall in the title.
Update2: When I had the wrong contents in NuGet.Config, I was seeing some developer channel (internal unreleased) builds.
Current output of dnvm list:
me@mabox:~$ dnvm list
Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
1.0.0-beta7 mono linux/osx
* 1.0.0-beta8 mono linux/osx default
Update 3: Once I installed coreclr target runtime type this issue went away. Once it's installed, dnvm list looks like this:
Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
* 1.0.0-beta8 coreclr x64 linux
1.0.0-beta8 mono linux/osx default
Update 4: Both answers below contain essential information. One mistake I made was to assume that the ancient mono-2.x versions that are included in the apt-get repos of Ubuntu 14.04 are acceptable for DNX usage. They are not, instead as of the date I am writing this, only recent mono-2015.11.xx nightly builds are known to work. At some point in future once a stable 4.3.0+ version is released, you would be using that, probably, with DNX, but I can't say for sure.
回答1:
The latest .Net and Visual Studio tooling on Windows is 1.0.0-beta8, and I have that also on my ubuntu box, which reports that Mono-x64-1.0.0-beta8-15858 is intalled.
To me it seems that you are not running against the same runtime.
Have you tried running a dnvm upgrade
without targeting the nightly build server? It looks to me that your code might be using beta8
assemblies on a beta8-15858
runtime.
Run dnu feeds list
on your Ubuntu box to make sure you are targeting the stable channel and not the developer one (should see only the default feed).
If you are targeting the wrong feed, you can change it from the nuget.config
file located in your user folder under ~/.config/NuGet/Nuget.Config
.
Do the following to ensure you are on the proper runtime:
- Delete all existing runtimes in
~/.dnx/runtimes
dnvm upgrade
dnvm install -r coreclr latest
- Then run
dnu restore
on your project dnx web
should now work
回答2:
It is possible to run beta8 against mono on ubuntu 14.04. I just gave it a shot and was successful, here's the steps I followed;
Installed dnvm and libuv per the instructions here.
Ran
dnvm install 1.0.0-beta8
Installed mono-snapshot-latest and executed
. mono-snapshot mono
Cloned this new MVC 6 beta8 project
git clone https://github.com/staff0rd/TinyMvc -b beta8
Ran
mozroots --import --sync
so nuget doesn't throw TrustFailure exceptionsExecuted
cd TinyMvc
anddnu restore
Run
dnx web
;
Result:
[mono-2015.11.13+00.47.00]root@8792d900344b:/TinyMvc# dnx web
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
Performed against an empty Ubuntu 14.04 from here.
来源:https://stackoverflow.com/questions/33675952/dnx-web-on-ubuntu-14-04-throws-system-runtime-interopservices-marshal-exceptio