Anton L.

Hi all,

When I add a new external type of List<CustomClass> I set the namespace to System.Collections.Generic. In the DomainClasses.tt and Serializer.tt templates I add the following lines:

<#@ assembly name = "CustomAssembly" #>
<#@ import namespace="CustomAssembly.CustomNamespace#>

When I save the templates and look at the generated code, the namespaces are not imported and the compilers gives me an error that CustomClass cannot be found (obviously). If I hack around it I can make it work by typing the namespace in plain text, but that's not something I want to do. What am I doing wrong here

Thanks in advance,
Anton


Re: Visual Studio Extensibility Generic List, namespace not imported

Edward Bakker

Hi,

Where is your custom assembly located You can use the strong name for the assemly if it is installed in the GAC. If not, you have to use the fully qualified assembly name (<#@ assembly name = "C:\Temp\MyCustomAssembly.dll" #>).

Hope this helps

Edward





Re: Visual Studio Extensibility Generic List, namespace not imported

Anton L.

Hi Edward,

The assembly that I'm trying to load is the DSL's own assembly. I've created a few classes in the DSL and I need them in the generated code.

There's nothing wrong with the assembly. If I add a non-existing assembly I recieve and error, saying that the assembly could not be found. For example:

<#@ assembly name = "CustomAssemblyNExist" #>
<#@ import namespace="CustomAssembly.CustomNamespace" #>

Gives me the following error:
Compiling transformation: The metadatafile CustomAssemblyNExist has not been found (had to translate this, so it is very well possible that the error is formulated differently).

Even if I specify the full path, the generated code still doesn't contain the namespace. The only namespaces I see are:

using DslModeling = global::Microsoft.VisualStudio.Modeling;
using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;

Any idea what's going on here

Regards,
Anton




Re: Visual Studio Extensibility Generic List, namespace not imported

Gokhan Altinoren

You may modify C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Tools\DSLTools\TextTemplates\Dsl\DomainClassCodeGenerator.tt etc. to include your own namespaces but definitely not a good idea.

By the way, why don't you define your external type as List<CustomAssembly.CustomNamespace.CustomClass> instead You won't have to include your assembly that way.




Re: Visual Studio Extensibility Generic List, namespace not imported

Pim Vendrig

That is a problem I have too.

I don't seem to be able to add an external type with a dot in it.
For example:
  • Namespace "System.Collections.Generic", Name "List<string>" works
  • Namespace "System.Collections.Generic", Name "List<System.String>" does not work. I get the errormessage "Supplied message does not have a Description. Parameter name: message.Description"
So when I want to add Company.Product.CustomNamespace.CustomType in the List, I have to specify "List<CustomType>". I transform the templates, and some errors appear, that the Type "CustomType" cannot be found.

Importing the namespace: <#@ import namespace="Company.Product.CustomNamespace" #> gives the error "Compiling transformation: The type or namespace Company cannot be found (Missing a assembly )"

So adding the namespace of my Dsl: <#@ assembly name="Company.Product.Dsl" #> removes that error.

However, a usingstatement is not created in the CS file.

Now I have hardcoded "using Company.Product.CustomNamespace;" in my .tt file, and the errors of not finding the Type "CustomType" are gone and the project works.

This is kind of dirty, so does anyone of you know why the using statement does not appear by itself, because I did add the "<#@ assembly" and "<#@ import" tags.





Re: Visual Studio Extensibility Generic List, namespace not imported

Anton L.

Hi Gokahn,

As Pim mentioned it is not possible to include dot's (.) in a domain type's name. If I do add dot's to include the namespace, I get the following error when I save the project:

Supplied message does not have a Description. Parameter name: message.Description.

(I assume that the error message could not be located ).

Regards,
Anton




Re: Visual Studio Extensibility Generic List, namespace not imported

Gokhan Altinoren

Right now, I have two external types with dots in the nameSmile Go figure Smile)) (One is List<System.String> to test Pim's case).

Here's one property definiton in XML from the Dsldefinition.dsl file when I view it with XML editor:

<DomainProperty Id="b0d78aac-cb2a-483c-93c9-b682243a338c" Description="List of additional imports to be added to the generated class." Name="AdditionalImports" DisplayName="Additional Imports" Kind="CustomStorage" Category="Code Generation">
<Type>
<ExternalTypeMoniker Name="/System.Collections.Generic/List&lt;Altinoren.ActiveWriter.Import&gt;" />
</Type>
</DomainProperty>

Here's external type definitions:

<Types>
....
<ExternalType Name="List&lt;Altinoren.ActiveWriter.Import&gt;" Namespace="System.Collections.Generic" />
<ExternalType Name="List&lt;System.String&gt;" Namespace="System.Collections.Generic" />
</Types>

You may try to edit .dsl file in xml and add them manually to test if it's an DSL Tools editor issue. Are you both using international versions of VS Can this be an internationalization issue The error message you get is really weird.




Re: Visual Studio Extensibility Generic List, namespace not imported

Edward Bakker

Pim,

Please note that the "Assembly" and "Import" directive are only used to allow you to use classes from other assemblies in your (control) code INSIDE the templates itself. They don't do anything with the templates output.

So, if you need a "using" statement in the output of your template, you have to "hardcode" that in the template! This is the way it works.

Edward





Re: Visual Studio Extensibility Generic List, namespace not imported

Anton L.

I did what you suggested and I changed the values in the xml. However if I want to open the DSL I get the following error: "Object reference not set to an instance of an object".

I don't know which version I have. Some error messages are in english while others are in my native language.




Re: Visual Studio Extensibility Generic List, namespace not imported

Edward Bakker

oops... I now notice this tread isn't about text templates at all :-). totally missed that it was about "external types" . I think I only looked at the "directives" and assumed text templating. So, please forget about all my reply's

Edward





Re: Visual Studio Extensibility Generic List, namespace not imported

Pim Vendrig

Thansks for your information.

I "just" need to adapt the External Type, so I don't have to use the using-statement.

However, just like Anton, I can't add a dot in the External Type.
I added a new external type, List<string>, saved succesfully.
Modified it in the XML at "ExternalType" to List<System.String>, opened the model again, and got the message "Supplied message does not have a Description. Parameter name: message.Description" again.
I believe Anton would have gotten the same message, but he also modified "
ExternalTypeMoniker", the reference to the ExternalType, and got another errormessage.

I also have messages in Dutch and English, so I guess that might be the problem if you haven't got that error. I use the version 2007.02.




Re: Visual Studio Extensibility Generic List, namespace not imported

GarethJ - MSFT

So I think we're dealing with two issues here.

1) As mentioned earlier in the thread, the <# import #> and <#@ assembly #> directives have no impact on what the output of a text template is. They're purely for allowing code inside the control blocks of the template to make use of whatever is imported. If you want you template output to contain a using method, then you should just put the "using MyNamespace" in the text of the template.

if you want that namespace to come from a model element you might make that parameterized from your model:

Code Snippet
using <#= someModelElement.Namespace #>;

for example, in the case of the DSL models:

Code Snippet

using <#= this.DslLibrary.Namespace #>;

2) Dots in external type names

This should work fine and it's a bug if it doesn't. I couldn't repro it on my machine, but I'm using all US English versions.

Which verison of DSL Tools/Visual Studio SDK are you using

What language Version of Visual Studio are you using

What language of Windows are you using






Re: Visual Studio Extensibility Generic List, namespace not imported

Pim Vendrig

Hi, these are my versions:

-Microsoft Windows XP, Dutch, Latest Windows Update
-Microsoft Visual Studio 2005 Professional Edition Version 8.0.50727.762 (SP.050727-7600)
-Microsoft .NET Framework Version 2.0.50727
-Visual Studio 2005 SDK Version 2007.02 (I have 2006.09 also installed, but my project references to 2007.02: <Import Project="$(ProgramFiles)\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Tools\Build\Microsoft.VsSDK.targets" /> )

I don't seem to be able to find the language of Visual Studio, but the entire menu is in English.
Only some errormessages are in dutch, so far only from the text templates: "Error 1 Compiling transformation: Het type of de naamruimtenaam Company is niet gevonden (ontbreekt er een gebruiksinstructie of assembly-verwijzing ) c:\Documents and Settings\pvendrig\Local Settings\Temp\9jnxxqxo.0.cs 2 11 "

Hope this gives some information,

Pim




Re: Visual Studio Extensibility Generic List, namespace not imported

Steve Cook MSFT

I'd like to be clear about whether this thread actually represents a problem or not. Pim, if you see this, what happens when you do the following

1. Open the DSL editor

2. Select the menu option "Add New External Type" on the Dsl explorer node that represents your language

3. Add a type with a name such as List<System.String> and a namespace such as System.Collections.Generic

4. Create a domain property on one of your domain classes

5. Use the dropdown in the property browser to give your new domain property the type that you just created

6. Validate, save, generate, build.

This should work. You should not need to go into the XML format of the DSL definition.