Forum:  Custom Templates

Thread:  lpt C# includeOnly template is generated as separate class


Jan VBM (User)   Posted on: 08-Aug-2014 14:01:46.
L.S.,

I'm trying to reuse/convert a whole set of templatebindings, tasks, etc. used in v3.5 now in v4.2

In that set of template files there are a few lpt templates (e.g. LptFkBuildParameterStrings) in C# which are labeled with includeOnly="true", which I understood means that no separate class is generated in the generator source; in stead the lpt file will only be used to complete the "calling" lpt template classes, by using a line like:
%>    <# LptFkBuildParameterStrings #> <%

When trying to generate source code, the "calling" lpt template classes are generated correctly but it also generates a separate class in the generator source for the IncludeOnly template; which gives an error like:
Quote:
Error Code Generation Cycle failed.
Error CS0103, at line: 447, pos: 112: The name 'relation' does not exist in the current context

obviously relation is a variable in the "calling" lpt script.

in templatebindings if have defined:
•    templateID="FkBuildParameterStrings"
•    filename="BusinessLogic\C#\fkBuildParameterStrings.lpt"
•    templateLanguage="C#"
•    includeOnly="true"

The first part of the generated class is presented below. Any ideas? How do I make sure an IncludeOnly template is only included in other templates (other than using the described settings)?

Quote:

public class FkBuildParameterStrings : ITemplateClass {
    private StreamWriter __outputWriter;
    private IGenerator _executingGenerator;
    private Dictionary<string, TaskParameter> _parameters;
    private string _templateID = "COWI_FkBuildParameterStrings";
    private string _templateBindingDefinitionName="COWI";
    private object _activeObject;

    public COWI_FkBuildParameterStrings() {
        __outputWriter=null;_executingGenerator=null;_parameters=null;_activeObject=null;
    }

    private void __ScriptCode() {
            String _forDatatypeParameter = "";
            String _forAttributeParameter = "";
            String _forParameter = "";
            String _forEntityDeleteParameter = "";
            String _forEntityAttributeParameter = "";
            String _forParameterCamelCase = "";
            String _forConcatParameter = "";
            String _forFilterFieldValue = "";

            String _relatedDatatypeParameter = "";
            String _relatedAttributeParameter = "";
            String _relatedParameter = "";
            String _relatedEntityDeleteParameter = "";
            String _relatedEntityAttributeParameter = "";
            String _relatedParameterCamelCase = "";
            String _relatedConcatParameter = "";
            String _relatedFilterFieldValue = "";
    
            int countfieldPairs = 1;
            foreach( SD.Tools.Algorithmia.GeneralDataStructures.Pair<IFieldElementCore, IFieldElementCore> fieldPair in relation.GetRelationshipFieldPairs() )
            {

Walaa (Support Team)   Posted on: 08-Aug-2014 16:12:26.
So you have set IncludeOnly to true in the templatebinding file, correct?

Jan VBM (User)   Posted on: 08-Aug-2014 17:12:05.
yes, i have tested with (true/false) an without this setting, behaviour is the same.

Quote:

<templateBinding templateID="FkBuildParameterStrings"            filename="BusinessLogic\C#\fkBuildParameterStrings.lpt"
templateLanguage="C#"
includeOnly="true" />
Otis (LLBLGen Pro Team)   Posted on: 08-Aug-2014 17:34:37.
I think it's a bug.

The lpt templates get a separate class for each template defined, except the ones which are marked "includeOnly='true'", those are left alone (as they're included into their including templates).

The problem occurs with the TDL parser, which compiles all lpt templates into a separate assembly for include purposes into TDL templates. It also gathers all include templates here and these thus get a separate class. If the lpt template can't stand alone as a class, it will thus fail as you see with your code.

The change is from before 2009, so that these have worked in 3.5 is a little odd. However the 'includeOnly' should prevent this problem and it doesn't so it's a bug.

The TDL parser assumes a template included into a TDL template is a full class, so with these includeOnly should be set to false (and the template should be able to stand on its own, which is in all cases the case as they're not included into some other lpt template.

I'll make a change to the lpt parser and this should fix it (it's a simple boolean change). I'll attach this parser to a follow up post.


Otis (LLBLGen Pro Team)   Posted on: 08-Aug-2014 17:57:08.
Fixed parser attached (debug build). Release build in next installer build (likely released on monday).

copy as administrator into <installation folder>\TaskPerformers
Jan VBM (User)   Posted on: 08-Aug-2014 18:32:24.
I get an error after copying the SD.LLBLGen.Pro.LptParser.dll in the TaskPerformer folder and running code generation cycle...

Code:
Exception message:
-------------------------------
Exception type: FileLoadException
Could not load file or assembly 'file:///C:\Program Files (x86)\Solutions Design\LLBLGen Pro v4.2\TaskPerformers\SD.LLBLGen.Pro.LptParser.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

Inner Exception message:
-------------------------------
An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.


Otis (LLBLGen Pro Team)   Posted on: 08-Aug-2014 18:45:02.
You have to 'unblock' the dll. (right-click it in explorer -> security). Anyway, I've attached the parser in a zip which circumvents this problem Wink
Jan VBM (User)   Posted on: 08-Aug-2014 19:13:09.
That did the trick, it works now, thanks a lot.

Otis (LLBLGen Pro Team)   Posted on: 03-Oct-2014 12:16:12.
This fix causes a problem at the moment. We're looking into making a change so your problem is still solved and this side effect (as in: lpt templates included in TDL templates are no longer working) is also solved. In the worse case scenario we have to roll back the fix but I hope this isn't necessary.
Otis (LLBLGen Pro Team)   Posted on: 03-Oct-2014 13:10:51.
We fixed it properly this time in the code generator. No action from you required, it should keep on working as it does now with the August 8th fix.