dnx web on ubuntu 14.04 throws “System.Runtime.InteropServices.Marshal” exception (1.0.0-beta8)

巧了我就是萌 提交于 2019-12-02 02:20:17

问题


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:

  1. 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>
  1. 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.)

  2. Clone your sources.

  3. Select a dnx version via dnvm use.

  4. Make sure your user-account-level dnx runtime packages are restored via dnu restore.

  5. ??What??

  6. 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;

  1. Installed dnvm and libuv per the instructions here.

  2. Ran dnvm install 1.0.0-beta8

  3. Installed mono-snapshot-latest and executed . mono-snapshot mono

  4. Cloned this new MVC 6 beta8 project git clone https://github.com/staff0rd/TinyMvc -b beta8

  5. Ran mozroots --import --sync so nuget doesn't throw TrustFailure exceptions

  6. Executed cd TinyMvc and dnu restore

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!