} expected using c# in biml

110 views Asked by At

I'm writing biml in visual studio and have a problem when using c#. I get an error saying "} expected" pointing to the closing bracket of the if statement, but I can't find where I'm missing something. I'm new to this and aware that there are probably other mistakes too :)

               <#foreach(var order in metaData.Attributes.Select(x => x.ORDER).Distinct()){#>
                    <Container Name="Sequence Container_<#=order#>">
                        <PrecedenceConstraints>
                            <#if (order == "0"){#>
                                <Inputs>
                                    <Input OutputPathName="Set IDRunMaster.Output"/>
                                </Inputs>
                            <#}#>
                            <#else{#>
                                <#int previousOrder = Int32.Parse(order) - 1;#>
                                <Inputs>
                                    <Input OutputPathName="Sequence Container_<#previousOrder#>"/>
                                </Inputs> 
                            <#}#>
                        </PrecedenceConstraints>
                        <Tasks>
                            <#foreach(var item in  metaData.Attributes.Where(y => y.ORDER == order).Select(x => x.ORIGINAL_OBJECT).Distinct()){#>
                                <ExecutePackage Name="DWH_<#=item#>">
                                    <ExternalProjectPackage Package="DWH_<#=item#>.dtsx" />
                                </ExecutePackage>
                            <#}#>
                        </Tasks>
                    </Container>
                <#}#>
1

There are 1 answers

1
billinkc On BEST ANSWER

First syntax error (not reported)

<Input OutputPathName="Sequence Container_<#previousOrder#>"/>

You're missing a semicolon here or you intended to use <#= here

<Input OutputPathName="Sequence Container_<#=previousOrder#>"/>

The reported error is weird and while I'm not fully awake, I don't see what the root cause is.

My approach was to format your code into what my brain expects with regard to brace placement.

This code still has the error about unmatched {

<#
// TODO: definition of metaData
// Needs to have ORDER and ORIGINAL_OBJECT attributes and be LINQable

#>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Packages>
        <Package Name="SO_70679838">
            <Tasks>
<#
               foreach(var order in metaData.Attributes.Select(x => x.ORDER).Distinct())
                 {
#>
                    <Container Name="Sequence Container_<#=order#>">
                        <PrecedenceConstraints>
<#
                            if (order == "0")
                            {
#>
                                <Inputs>
                                    <Input OutputPathName="Set IDRunMaster.Output"/>
                                </Inputs>
<#
                            }
#>
                            <#
                            else{
#>
                                <#int previousOrder = Int32.Parse(order) - 1;#>
                                <Inputs>
                                    <Input OutputPathName="Sequence Container_<#=previousOrder#>"/>
                                </Inputs> 
                            <#}#>
                        </PrecedenceConstraints>
                        <Tasks>
                            <#foreach(var item in  metaData.Attributes.Where(y => y.ORDER == order).Select(x => x.ORIGINAL_OBJECT).Distinct()){#>
                                <ExecutePackage Name="DWH_<#=item#>">
                                    <ExternalProjectPackage Package="DWH_<#=item#>.dtsx" />
                                </ExecutePackage>
                            <#}#>
                        </Tasks>
                    </Container>
                <#}#>
            </Tasks>
        </Package>
    </Packages>
</Biml>

This, does not

<#
// TODO: definition of metaData
// Needs to have ORDER and ORIGINAL_OBJECT attributes and be LINQable

#>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Packages>
        <Package Name="SO_70679838">
            <Tasks>
<#
               foreach(var order in metaData.Attributes.Select(x => x.ORDER).Distinct())
                 {
#>
                    <Container Name="Sequence Container_<#=order#>">
                        <PrecedenceConstraints>
<#
                            if (order == "0")
                            {
#>
                                <Inputs>
                                    <Input OutputPathName="Set IDRunMaster.Output"/>
                                </Inputs>
<#
                            }
#>
<#
                            else{
#>
                                <#int previousOrder = Int32.Parse(order) - 1;#>
                                <Inputs>
                                    <Input OutputPathName="Sequence Container_<#=previousOrder#>"/>
                                </Inputs> 
                            <#}#>
                        </PrecedenceConstraints>
                        <Tasks>
                            <#foreach(var item in  metaData.Attributes.Where(y => y.ORDER == order).Select(x => x.ORIGINAL_OBJECT).Distinct()){#>
                                <ExecutePackage Name="DWH_<#=item#>">
                                    <ExternalProjectPackage Package="DWH_<#=item#>.dtsx" />
                                </ExecutePackage>
                            <#}#>
                        </Tasks>
                    </Container>
                <#}#>
            </Tasks>
        </Package>
    </Packages>
</Biml>

all I did was eliminate the leading space in front of the directive in the else clause.

Going back to your original version, same thing. So, something in line 17 is making things go haywire but as I don't have a working minimal reproduction, I can't say for certain what you have wrong.

<#
// TODO: definition of metaData
// Needs to have ORDER and ORIGINAL_OBJECT attributes and be LINQable
#>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Packages>
        <Package Name="SO_70679838">
            <Tasks>
              <#foreach(var order in metaData.Attributes.Select(x => x.ORDER).Distinct()){#>
                    <Container Name="Sequence Container_<#=order#>">
                        <PrecedenceConstraints>
                            <#if (order == "0"){#>
                                <Inputs>
                                    <Input OutputPathName="Set IDRunMaster.Output"/>
                                </Inputs>
                            <#}#>
<#else{#>
                                <#int previousOrder = Int32.Parse(order) - 1;#>
                                <Inputs>
                                    <Input OutputPathName="Sequence Container_<#=previousOrder#>"/>
                                </Inputs> 
                            <#}#>
                        </PrecedenceConstraints>
                        <Tasks>
                            <#foreach(var item in  metaData.Attributes.Where(y => y.ORDER == order).Select(x => x.ORIGINAL_OBJECT).Distinct()){#>
                                <ExecutePackage Name="DWH_<#=item#>">
                                    <ExternalProjectPackage Package="DWH_<#=item#>.dtsx" />
                                </ExecutePackage>
                            <#}#>
                        </Tasks>
                    </Container>
                <#}#>   
            </Tasks>
        </Package>
    </Packages>
</Biml>

You can also make the error go away with the following but still just bandage over a shotgun wound

                        <#if (order == "0"){#>
                            <Inputs>
                                <Input OutputPathName="Set IDRunMaster.Output"/>
                            </Inputs>
                        <#}else{#>

This isn't python or FORTRAN so whitespace should not be the culprit and yet, here we are