System.Data assembly

Posts   
 
    
nfoscolos
User
Posts: 12
Joined: 20-Sep-2007
# Posted on: 09-Nov-2007 15:17:40   

I am using LLBLGEN Pro 2.5 and Template Studio 2.5.

I need to create a new task that requires access to system.data namespace. When I add this namespace to my template ie: <[System.Data]> the template will not compile but returns an error:

Comile Error: CS0234: The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

The taskperformer is SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine.

any suggestions?

thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 09-Nov-2007 20:33:27   

Please post or attach the template you're running and also, in template studio, create a debug build (set the debug build to the first task issuing .lpt templates) and check the generated C# code which runs the actual template (a .lpt template is converted to a piece of code, which is then compiled. This code isn't compilable in your case, and template studio can show you where that happens)

Frans Bouma | Lead developer LLBLGen Pro
nfoscolos
User
Posts: 12
Joined: 20-Sep-2007
# Posted on: 12-Nov-2007 15:01:38   

I don't think that it is related to my template code. I get this error when I add <[System.Data]> at the top of an existing template.

I simply added <[System.Data]> to the top of defaultCode.lpt (SD.AdditionalTempaltes.DbEnditor.Net20 -> SD_DefaultCode).


  <[System.Data]>
  using System;
  using System.Data;
  using System.Configuration;
  using System.Web;
  ...

When I generate the code I get an exception

Compilation of templates threw errors: Error CS0234, at line: 14, pos: 14: The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

The generated code is:

using SD.LLBLGen.Pro.ApplicationCore.StoredProcedures;
using SD.LLBLGen.Pro.ApplicationCore.Templates;
using System.Collections;
using SD.LLBLGen.Pro.ApplicationCore.Entities;
using System;
using SD.LLBLGen.Pro.ApplicationCore.Tasks;
using SD.LLBLGen.Pro.LptParser;
using System.IO;
using System.Diagnostics;
using SD.LLBLGen.Pro.ApplicationCore.TypedLists;
using SD.LLBLGen.Pro.DBDriverCore;
using System.Text;
using SD.LLBLGen.Pro.ApplicationCore.TypedViews;
using System.Data;
using SD.LLBLGen.Pro.ApplicationCore;
using SD.LLBLGen.Pro.GeneratorCore;
using System.Collections.Generic;
using System.ComponentModel;

line 14 is using System.Data;

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 13-Nov-2007 12:31:50   

<[System.Data]> using System; using System.Data; using System.Configuration; using System.Web;

I don't have much experience with lpt templates, but doesn't a using to the System.Data already exists?

Maybe you need to put it under the the using System. line, as follows:

using System;
<[System.Data]>
using System.Configuration;
using System.Web;
nfoscolos
User
Posts: 12
Joined: 20-Sep-2007
# Posted on: 13-Nov-2007 15:35:07   

No, <[System.Data]> is template code (generator input)

and

using System;
using System.Data;
using System.Configuration;
using System.Web;

is part of the generator output.

The generator seems to create the intermediate cs file correctly (see below) line 14 'using System.Data'.

using SD.LLBLGen.Pro.ApplicationCore.StoredProcedures;
using SD.LLBLGen.Pro.ApplicationCore.Templates;
using System.Collections;
using SD.LLBLGen.Pro.ApplicationCore.Entities;
using System;
using SD.LLBLGen.Pro.ApplicationCore.Tasks;
using SD.LLBLGen.Pro.LptParser;
using System.IO;
using System.Diagnostics;
using SD.LLBLGen.Pro.ApplicationCore.TypedLists;
using SD.LLBLGen.Pro.DBDriverCore;
using System.Text;
using SD.LLBLGen.Pro.ApplicationCore.TypedViews;
using System.Data;
using SD.LLBLGen.Pro.ApplicationCore;
using SD.LLBLGen.Pro.GeneratorCore;
using System.Collections.Generic;
using System.ComponentModel;
...

The error occurs during the Code Generation step when this cs file is compiled. It sounds like a project reference (link time) error.

It should be easy to reproduce by adding <[System.Data]> at the top of one of the SD.AdditionalTempaltes.DbEnditor.Net20 templates. (ie defaultCode.lpt) and then compiling the templates.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 14-Nov-2007 15:39:31   

Ah, I understand simple_smile

You make a typical mistake, let me explain simple_smile The .lpt template contents is first generated into C# or VB.NET code (lets call this code ABC). THAT code (ABC) is then compiled into an assembly and ran to generate the actual outputcode (DEF).

The <[System.Data]> Namespace reference is used to specify that the TEMPLATE CODE ABC (thus the code generated from the template which will be compiled into an assembly) uses System.Data, and thus that THAT code has to have using System.Data at the top. This ALSO means that if you want to do that, you have to add an assembly reference to System.Data. This is what you should do as well.

However, if you want to have a line using System.Data;

in the OUTPUT (thus code DEF), you can just add that line to the template text (thus outside <%%> blocks).

I hope this makes sense.

Frans Bouma | Lead developer LLBLGen Pro
nfoscolos
User
Posts: 12
Joined: 20-Sep-2007
# Posted on: 14-Nov-2007 16:41:40   

Thanks Frans,

I am trying to build an lpt template that accesses the database. The template will read a db view and generate enums for lookup values. So, the ABC code does need the "using System.Data" line (not the output).

So, I guess the question is how do I add an Assembly reference for system.data, so, that it is available during the ABC code compilation.

Sorry for the confusion. (I think we need a new terminology standard for all these extra stepswink )

Nick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 14-Nov-2007 18:52:38   

<$ full path + filename of assembly $> Example: <$ c:\program files\Solutions Design\LLBLGen Pro\RuntimeLibraries\DotNet11\SD.LLBLGen.Pro.ORMSupportClasses.dll $>

See: SDK Docs -> Templates and templatebindings -> Lpt templates engine

Frans Bouma | Lead developer LLBLGen Pro
nfoscolos
User
Posts: 12
Joined: 20-Sep-2007
# Posted on: 14-Nov-2007 20:30:45   

That worked!

Thanks!