Ken的杂谈
  • Ken的杂谈 (current)
  • 关于
  • 杂谈
    Java Spring Spring Boot Spring Cloud MyBatis C# .NET Core .NET ASP.NET Core ASP.NET ClassLibrary Mono 数据库 MySQL SQL Server 网络 缓存 Web Linux CentOS Ubuntu macOS Nginx Windows ServiceStack JS/JQ 正则 工具 IDE Grafana Exceptions CI/CD Solution 微服务 Arch Docker 杂谈
  • 系列
    Java 快速入门系列教程 Spring Boot 入门教程 Spring Boot 2.x 入门教程 Spring Cloud 入门教程 .NET Core 快速入门教程 ASP.NET Core 2.1 入门教程 CentOS 7 快速上手教程 Ubuntu快速上手入门教程 Hyper-V基础教程 Docker入门教程
  • GitHub

【问题解决】Mono下部署ASP.NET应用提示:System.IO.FileNotFoundException

Exceptions Mono Spring @ 2017-07-04 21:08:14 · 阅读:(6042)

一、前言

  • 本篇文章解决办法适用范围?
  1. 错误提示为找不到roslyn编译器
    (通常项目为VS2107创建会碰到这个问题)

二、问题分析

  • 错误信息

image

System.IO.FileNotFoundException
Could not find file "/mysiteroot/bin\roslyn\csc.exe".

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0019c] in <3753d1715b8842d8bb13a30db0388b60>:0
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <3753d1715b8842d8bb13a30db0388b60>:0
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at System.IO.File.OpenRead (System.String path) [0x00000] in <3753d1715b8842d8bb13a30db0388b60>:0
  at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.get_CompilerName () [0x00019] in <13231d2f854e4437bf639e10b63dd37e>:0
  at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.FromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00168] in <13231d2f854e4437bf639e10b63dd37e>:0
  at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.CompileAssemblyFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00048] in <13231d2f854e4437bf639e10b63dd37e>:0
  at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00006] in <1d7393d853954016b607e8e348b00ad1>:0
  at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) [0x0029f] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath) [0x00008] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.Compilation.BuildManager.GenerateAssembly (System.Web.Compilation.AssemblyBuilder abuilder, System.Web.Compilation.BuildProviderGroup group, System.Web.VirtualPath vp, System.Boolean debug) [0x00202] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, System.Boolean debug) [0x00106] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.Compilation.BuildManager.Build (System.Web.VirtualPath vp) [0x00058] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.Compilation.BuildManager.GetCompiledType (System.Web.VirtualPath virtualPath) [0x00037] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) [0x00006] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.HttpApplicationFactory.InitType (System.Web.HttpContext context) [0x00219] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.HttpApplicationFactory.GetApplication (System.Web.HttpContext context) [0x00018] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
  at System.Web.HttpRuntime.Process (System.Web.HttpWorkerRequest req) [0x00052] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0

实际错误诱因:

Could not find file "/mysiteroot/bin\roslyn\csc.exe".

也就是站点启动时找不到站点根目录bin文件夹中的roslyn编译器
由于Mono不兼容roslyn那我们只能考虑改用msbuild
一个项目的编译信息是由.csproj文件存储的,那具体怎么解决这个问题
就只能从这个文件入手

分析.csproj文件发现跟roslyn相关的配置

 <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />

也就是说项目中安装了如下两个package:

Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers

三、解决办法

#通过nuget卸载这两个package即可
uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
uninstall-package Microsoft.Net.Compilers

Ken的杂谈

本文由 ken.io 创作,采用CC BY 3.0 CN协议 进行许可。 可自由转载、引用、甚至修改,但需署名作者且注明出处。

Exceptions Mono Spring

随笔目录


    © Copyright 2012-2023 Ken的杂谈

    豫ICP备10025012号-1

    ASP.NET Core(6.0) on Linux