none
UDT Type Equivalence in .NET 4.0 RRS feed

  • Question

  • Hi,

    I have a Primary Interop Assembly with .NET class representing a UDT from COM (DateTimeWrapper). In .NET 3.5 it was possible to customize such a class and to add additional methods, derive it from various interfaces etc. In .NET 4.0, however, this is not possible (because of type equivalence?). The thing is that I have an OLE DB provider that returns VARIANT values. In ADO.NET these values are marshalled into .NET values by the COM interop that uses the PIA. When I display the result in .NET 3.5 application (in a grid) I see a nice value (because I implement DateTimeWrapper::ToString() in the PIA). In a .NET 4.0 application it is more complicated. With my customized implementation of DateTimeWrapper an exception is thrown:

    System.TypeLoadException: Could not load the structure 'DateTimeWrapper' from assembly 'PIOLEDBENT, Version=1.2.0.0, Culture=neutral, PublicKeyToken=53b77d1d3d7a979b'. The structure is marked as eligible for type equivalence, but it has a method.

    When I remove all the methods from the DateTimeWrapper class, a value is displayed without any exception; however its content is "DateTimeWrapper" which is obviously bad.

    It seems to me ridiculous that I cannot override at least the ToString method which is already on Object class without breaking the type equivalence. Do you have any idea what I can do? Do you think this is a bug that should be reported to Microsoft?

     [
     StructLayout(LayoutKind::Sequential, Pack = 8),
     Guid("978AEE4A-C149-3E92-9EED-2FA8CA4AF61F")
     ]
     public value class DateTimeWrapper
     {
     public:
     long long _fileTime;
    
     public:
     virtual String^ ToString() override
     {
     return DateTime::SpecifyKind(DateTime::FromFileTimeUtc(_fileTime), DateTimeKind::Local).ToString();
     }
     };
    

     




    Monday, August 29, 2011 4:21 PM

Answers

All replies