Search code examples
c#c1-cms

Cannot add or modify datatype on modified C1 CMS


Since C1 CMS' built-in image resizer cannot enlarge images I've added modified image resizer library and modified the line below:

// using Composite.Core.WebClient.Media;
using Composite.Core.WebClient.Media.Modded;

Modified files are:

C:\NET\vhosts\C1.CMS.6.6\Website\Composite\services\Media\ImageManipulator.ashx
C:\NET\vhosts\C1.CMS.6.6\Website\Renderers\ShowMedia.ashx

Modified image resizer source codes are located under the folder:

App_Code\ImageResizerModded

enter image description here

Now everything works as perfect... Until I try to add new datatype or modify any. When I do that I got an error:

enter image description here

The line is untouched original source code which works perfectly:

enter image description here

The Stackoverflow answer says about => syntax:

enter image description here

I don't know what's wrong here and how to fix it. The only workaround is to delete ImageResizerModded folder temporarily, modify/add datatype and then undelete the folder. The online site (pictures) affects for a while during the folder is deleted.

How can I fix the issue?


Solution

  • This is due to the compiler used by C1 CMS to do the static checking if changes you made will compile is hardcoded to an old compiler version and not the current Roslyn compiler otherwise shipped in the bin-folder.

    In your case C1 CMS compiles the app_code in-memory in this method https://github.com/Orckestra/C1-CMS-Foundation/blob/67275baf443c303623fd1f1ab43721a8e0efdd4f/Composite/Core/Types/CodeCompatibilityChecker.cs#L63, but a quick search shows the CSharpCodeProvider being used in 6 different places https://github.com/Orckestra/C1-CMS-Foundation/search?q=CSharpCodeProvider&unscoped_q=CSharpCodeProvider

    This use of CSharpCodeProvider would need to be replaced with Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider

    So the behavior you see is expected and you can get around it by

    1. Temporarily removing the files during datatype change as you found out yourself
    2. Don't use C# 6 or newer in app_code
    3. Ship code using C# 6 or newer in a compiled assembly
    4. Use static datatypes (C# interfaces) instead of dynamic