Search code examples
c#asp.netasp.net-mvciisckfinder

CKFinder Zip installation CodeDom Provider Type exception


Attempting to install CkFinder as subsite to an ASP.NET MVC web application per ckfinder documentation, via the ZIP download option. The main MVC site is operating normally, but could not add CKFinder via nuget because of conflicting version information in a required library.

Sandbox test involved adding ckfinder as a subsite to an ASP.NET webforms application, which appeared to work flawlessly right away with only a couple configuration issues.

Now, I added the subsite to one of the "Areas" of the MVC app, and this caused the same exception I will describe in a moment. Changing the path to the recommended /ckfinder path did not really make a difference. After installing everything I go to the ckfinder path and get the ugly ASP.NET error page, and if I go to the ckfinder sample page, the ugly error shows up in a popup window. In Event viewer, this exception is recorded:

Exception information: 
    Exception type: HttpException 
    Exception message: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. (C:\webs\MainSite\web.config line 369)
   at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
   at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
   at System.Web.Compilation.BuildManager.CallAppInitializeMethod()
   at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. (C:\webs\MainSite\web.config line 369)
   at System.CodeDom.Compiler.CompilerInfo.get_CodeDomProviderType()
   at System.Web.Configuration.CompilationSection.GetCompilerInfoFromExtension(String extension, Boolean throwOnFail)
   at System.Web.Compilation.CompilationUtil.GetBuildProviderTypeFromExtension(CompilationSection config, String extension, BuildProviderAppliesTo neededFor, Boolean failIfUnknown)
   at System.Web.Compilation.BuildManager.CreateBuildProvider(VirtualPath virtualPath, BuildProviderAppliesTo neededFor, CompilationSection compConfig, ICollection referencedAssemblies, Boolean failIfUnknown)
   at System.Web.Compilation.CodeDirectoryCompiler.ProcessDirectoryRecursive(VirtualDirectory vdir, Boolean topLevel)
   at System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed)
   at System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories)
   at System.Web.Compilation.BuildManager.CompileCodeDirectories()
   at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()

The codedom libraries ARE referenced in the web.config file for the main site, but the ckeditor site does not reference them.

So it looks like in the exception it's trying to find the roslyn library from the main site, and as I said ckFinder is installed as a subsite. The two sites are actually not even installed on the same disk on the server.

** Update **

I removed roslyn from the parent application (a separate, standalone solution in ASP.NET 4.6.2, MVC) and now CKFinder works. However, removing the roslyn/codedom package seems to have broken other features.

Namely I get the new error:

Error   CS8026  Feature 'null propagating operator' is not available in C# 5. Please use language version 6 or greater.

This error seems odd as Microsoft says I should be running at least C# 7.3 with Visual Studio 2019 and the .NET version 4.6.2. The project says "latest version" for the C# version in the advanced configuration.


Solution

  • Because the folder with CKFinder is hosted (from IIS perspective) within the folder of your main application, it inherits all the settings from the web.config file of the main application.

    This includes the setting for the compiler provider. So, because the web.config of the main application is applied to the CKFinder project, the compiler provider assembly is searched when the CKFinder project is executed but cannot be found. I see four different approaches:

    1 Combine into one project

    Actually incorporate the CKFinder stuff into your main application so that you have only one Visual Studio web project

    2 Host as siblings

    Host them as siblings on the server and not one within the other (i.e. main application at http://localhost/MainApp/ and CKFinder project at http://localhost/ckfinder/) or using different subdomains.

    3 Add Compiler to CKFinder app

    Open the CKFinder subsite folder in Visual Studio and add the Microsoft.CodeDom.Providers.DotNetCompilerPlatform Version 2.0.1 nuget package so that the searched assembly compiler provider assembly is also present in the CKFinder app and can be found there.

    4 Prevent main app from applying compiler options to child apps

    Modify the web.config of the main application so that compiler provider settings are not passed on to child applications by embedding the system.codedom inside a location node:

    <location path="." inheritInChildApplications="false">
        <system.codedom>
          <compilers>
            <compiler language="c#;cs;csharp" extension=".cs" ....
            <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" ....
          </compilers>
        </system.codedom>
    </location>
    

    See also https://learn.microsoft.com/en-us/dotnet/api/system.configuration.sectioninformation.inheritinchildapplications


    If none of this works you should provide a Minimal reproducible example.