12

What are the implications of using Generic types in .NET to store ArcObjects, such as ILayer, IField, etc?

The compiler throws me a warning when using these kind of values

public class Foo
{
 private List<ILayer> fooLayers;
 public List<ILayer> FooLayers
 {
 get { ... }
 set { ... }
 }
}

Here is the warning:

Warning 15 Type library exporter warning processing 'ArcMemorialCore.Topography.IMemorialDocument.set_ProfessionalsEnvolved(value), ArcMemorialCore'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM. ArcMemorialCore

My concern is not only the warning's existence, but of good design practices, performance, etc.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 22, 2010 at 19:08
6
  • What warning are you getting? Commented Jul 22, 2010 at 19:09
  • 4
    Please add some context to your question too. We need to know more about how you are using the objects. As far as I know there are no inherent problems with using ArcObjects classes or interfaces like this. Commented Jul 22, 2010 at 19:12
  • What do the warnings say? Commented Jul 22, 2010 at 19:14
  • Are you getting an error or a warning? Commented Jul 22, 2010 at 19:15
  • Warning. It compiles just fine. My interests are beyond the existence of the warning. It's more of a concern in terms of performance, good design practices, etc. The warning is: Warning 15 Type library exporter warning processing 'ArcMemorialCore.Topography.IMemorialDocument.set_ProfessionalsEnvolved(value), ArcMemorialCore'. Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM. Commented Jul 22, 2010 at 19:38

2 Answers 2

11

The warning you received is because you have your class (or assembly) marked with:

[ComVisible(true)]

This causes the compiler to issue warnings when you use types that are not compatible with COM objects.

That being said, there is no problem with using generics with ArcObject types. You should, however, only use them for types that are internal to your application - ie: when you're working with a set of values.

answered Jul 22, 2010 at 19:52
3
  • Adding to this I believe it is only a problem for COM+ to refer to a generic type name, for example List<object>. Going from CLR to COM+ should not be a problem. Commented Jul 23, 2010 at 15:49
  • 1
    You can avoid this sort of warnings by marking your property as [ComVisible(false)] while still allowing the class (or whole assembly, which is not recommended practice in .NET 2.0+) to be marked as [ComVisible(true)]. Commented Aug 2, 2010 at 19:33
  • For reference: Interoperating Using Generic Types Commented Mar 14, 2011 at 15:12
2

I don't have an issue getting it to compile.

I am using C# 3.5

using System; 
using System.Collections.Generic; 
using System.Web;
using ESRI.ArcGIS.Carto; //Perhaps not having this reference is the issue?
public class Foo
 {
 private List<ILayer> _fooLayers;
 public List<ILayer> FooLayers
 {
 get { return _fooLayers; }
 set { _fooLayers = value; }
 }
 }
Nathan W
35.1k5 gold badges100 silver badges148 bronze badges
answered Jul 22, 2010 at 19:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.