Home All Groups Group Topic Archive Search About

TypeForwardedToApp attribute.

Author
12 Jul 2006 1:30 PM
CaffieneRush
Hi,

TypeForwardedToApp is one of the attributes covered in the MS upgrade
exam 70-553 http://www.microsoft.com/learning/exams/70-553.asp.

I've tried to code a short example in vb.net to test my understanding
of the attribute.
Unfortunetely, I could not get the attribute to work in vb.net (program
throws a TypeLoadException).
What's strange is that the c# examples using the same driver do work.

I wonder if anyone here has managed to get the TypeForwardedToApp
attribute to work in vb.net? Or perhaps knows what I'm doing wrong in
the vb.net examples.

Regards,
Andy

---
Module1.vb
---
Imports MyNamespace
'The test driver
Namespace TypeForwardedTo
    Module Module1

        Sub Main()
            Dim c As New Class1
        End Sub

    End Module
End Namespace

---
Class1.vb in ClassLibrary1VB assembly
---
<Assembly:
System.Runtime.CompilerServices.TypeForwardedTo(GetType(MyNamespace.Class1))>

Namespace MyNamespace
    'In ClassLibrary1VB assembly
    'Public Class Class1
    '    Public Sub New()
    '        Console.WriteLine("In ClassLibrary1VB assembly")
    '    End Sub
    'End Class
End Namespace

---
Class1.vb in ClassLibrary2VB assembly
---
Namespace MyNamespace
    Public Class Class1
        Public Sub New()
            Console.WriteLine("In ClassLibrary2VB assembly")
        End Sub
    End Class
End Namespace

---
Class1.cs in ClassLibrary1CS assembly
---
[assembly:
System.Runtime.CompilerServices.TypeForwardedTo(typeof(MyNamespace.Class1))
]
//using System;
//using System.Collections.Generic;
//using System.Text;

namespace MyNamespace
{
    //public class Class1
    //{
    //    public Class1()
    //    {
    //        Console.WriteLine("In the ClassLibrary1CS assembly");
    //    }

    //}
}

---
Class1.cs in ClassLibrary2CS assembly
---
using System;
using System.Collections.Generic;
using System.Text;

namespace MyNamespace
{
    public class Class1
    {
        public Class1()
        {
            Console.WriteLine("In the ClassLibrary2CS assembly");
        }

    }
}

Author
12 Jul 2006 4:51 PM
Mattias Sjögren
Andy,

Make sure that the root namespace of the projects are either equal or
cleared. Otherwise you'll have two different types
"ClassLibrary1VB.MyNamespace.Class1" and
"ClassLibrary2VB.MyNamespace.Class1". The full type name must be the
same for the attribute to work.



Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
12 Jul 2006 10:45 PM
CaffieneRush
Thanks Mattias,

Unfortunately, clearing both VB class library root namespace and
setting both root namespaces equally still raises that particular
exception.

At least the c# examples work, so I know what the
TypeForwardedToAppAttribute is supposed to do and where it might be
useful. I'm just a bit disappointed because I mainly work using vb.net.

Regards,
Andy