Self instantiation in static initializer

Steve Hannah <[email protected]> Mon, 25 Jan 2016 10:34:07 -0800
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <CABiRg+QK3Jnhc+Dwrx-fuyfK5boyKGjce783v+LNLbZBrL0-zQ@mail.gmail.com>
I have run into a problem trying to load classes in IKVM that include the
following pattern:

class Foo {
    static Foo instance = new Foo();

    ...

}


I'm getting errors as soon as I try to use the class at all.

System.MethodAccessException:
Attempt by method 'IKVM.Internal.ReflectUtil.isReflectionOnly(Type)' to
access method 'System.Reflection.Assembly.get_IsReflectionOnly(Type)'
failed.

The error occurs on this line
https://github.com/gluck/ikvm/blob/master/runtime/ReflectUtil.cs#L85

A first naive attempt at a fix was to just wrap that line in a try/catch.
But then I get a similar error on this line:
https://github.com/gluck/ikvm/blob/master/runtime/AssemblyClassLoader.cs#L74

[image: Inline image 1]

If I change the pattern to something like:

class Foo {
    static Foo instance = null;

    static Foo getInstance() {
        if (instance == null) instance = new Foo();
        return instance;
    }

}

It works fine.


I am working with a slightly modified source base for IKVM to try to build
UWP apps.  I'm following some of the suggestions from previous threads on
the issue (e.g. -noautoserialization, -t:net-2.0, etc.. for building)

Is this a known issue?  Any suggestions on a way to work around this?

Any help appreciated.

Best regards

Steve

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

_______________________________________________
Ikvm-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ikvm-developers
image.png (image/png, 238.3 KB) - not displayed