Search code examples
c#.netcompositec1-cms

Can composite.generated.dll complete rebuild itself if it is nonexistent?


I know if you are using Visual Studio that if you remove the composite.generated.dll it can rebuild and create a new file, but if that file on production gets removed for some reason, can it rebuild. I have done some testing and came to the assumption that it can't, but just wanted to make sure I am not missing something that can be done to complete rebuild the composite.genereated.dll in the bin if for some chance it didn't exist.


Solution

  • TL;DR

    Make sure not to have any Dynamic Datatypes, and if you do, make sure that no code in your App_Code is referencing your Dynamic Types.

    Long version

    Composite.Generated.dll contains classes implementing all your datatypes/interfaces which are dynamically compiled at runtime to target the DataProvider which containst the data for a type.

    When you work with Static Types, that is, Interface files created in your solution, all your code will be referencing them and there is no reference to Composite.Generated.dll at any point and your website is free to start up and Composite can go ahead and re-compile the Composite.Generated.dll if its missing or out-of-date.

    When working with Dynamic Types, you don't create any Interface File but build up the type using the CMS Editor. What happens behind the scenes is that Composite will create a Interface for you and add it to Composite.Generated.dll, which allows for code within App_Code to discover and reference this interface. The problem now is that you have a cyclic dependency; in case you delete Composite.Generated.dll the website cannot start, since it will automatically try to compile all code in App_Code first, which will fail since it references an interface which no longer exists. And because of this, Composite cannot start and re-compile Composite.Generated.dll - a classic chicken and egg problem.

    I quick-fix for this scenario is to move all files out of App_Code which will allow for the website to start, Composite can re-compile the Composite.Generated.dll file and you can move the files back to App_Code.

    A more robust solution is to just forget about Dynamic Types in production. Its great for fast prototyping during development, but gives too much headaches on production sites.