Search Issue Tracker

Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.

Postponed

Votes

1

Found in

4.3.1f1

Issue ID

585987

Regression

No

Unity is unable to call a static method of an nested generic class

Scripting

-

"TypeLoadException: A type load exception has occurred" error is thrown when calling a static method of a nested class

Comments (2)

  1. tmcsweeneyML

    Feb 03, 2015 20:25

    Well that was a formatting fail.

  2. tmcsweeneyML

    Feb 03, 2015 20:25

    I've run in to the same problem.

    The following code fails in unity at runtime with the "TypeLoadException: A type load exception has occurred" error, but works fine in .net

    [code]
    TestChannel.Gizmos.Draw();
    TestChannel2.Gizmos.Draw();

    [/code]

    [code]
    public static class NestedGenricTest {
    public class Channel<T> where T : Channel<T>, new() {
    private static T s_ChannelInstance;

    private static T Instance {
    get {
    if (s_ChannelInstance == null) {
    s_ChannelInstance = new T();
    }
    return s_ChannelInstance;
    }
    }

    private string m_Name;

    protected Channel(string name) {
    m_Name = name;
    }

    public static class Nested {
    public static void Draw() {
    Console.WriteLine("{0}.Draw()",Instance.m_Name);
    }
    }
    }
    }

    public class TestChannel : NestedGenricTest.Channel<TestChannel> {
    public TestChannel() : base("TestChannel") {

    }
    }
    public class TestChannel2 : NestedGenricTest.Channel<TestChannel2> {
    public TestChannel2() : base("TestChannel2") {

    }
    }
    [/code]

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.