0

I have a PoC to use some existing Java-codebase in some UWP-app using the most current Visual Studio Community 19 version 16.3.2 and the latest released IKVM 8.1.7195.0. The app builds and runs fine in Debug-mode, but fails to build already in Release-mode with the following error:

MCG0004:InternalAssert Assert Failed: ICE: trying to add a local var with the same name, but different types. during [_RegisterClipboardFormat] Ams.Oms.Poc

RegisterClipboardFormat is part of IKVM:

@DllImportAttribute.Annotation(value = "user32.dll", EntryPoint = "RegisterClipboardFormat")
private native static int _RegisterClipboardFormat(String format);

@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
private static int RegisterClipboardFormat(String format)
{
    return _RegisterClipboardFormat(format);
}

https://github.com/ikvm-revived/ikvm/blob/master/openjdk/sun/awt/IkvmDataTransferer.java#L95

What I'm wondering is which local variable the error message is referring to? Might be something added implicitly or might have to do with String in Java vs. string in C#? OTOH that file is clearly named .java.

Didn't find much about the error message in general, only the following two links seems to be more interesting:

Variables having same name but different type Why doesn't C# allow me to use the same variable name in different scopes?

So I'm currently even unsure where the message comes from, Visual Studio/C# directly or IKVM during running code during building Release-mode. I strongly suspect the error is coming from Visual Studio/C#, though.

Searching for the function itself doesn't reveal much of help as well:

Sorry, AWT is not a supported part of IKVM.

https://sourceforge.net/p/ikvm/bugs/225/

Others seemed to have the same problem, because CN1 simply disabled that code entirely in their fork of IKVM:

//@DllImportAttribute.Annotation(value = "user32.dll", EntryPoint = "RegisterClipboardFormat")
//private native static int _RegisterClipboardFormat(String format);

@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
private static int RegisterClipboardFormat(String format)
{
    throw new Error("Not implemented");
    //return _RegisterClipboardFormat(format);
}

https://github.com/ams-ts-ikvm/cn1-ikvm-uwp/blob/master/openjdk/sun/awt/IkvmDataTransferer.java#L95

Any ideas? Thanks!

Thorsten Schöning
  • 3,501
  • 2
  • 25
  • 46
  • Created some issues regarding this problem for further investigation: https://github.com/ikvm-revived/ikvm/issues/1 and https://github.com/ikvm-revived/ikvm/issues/3 – Thorsten Schöning Oct 24 '19 at 13:34

1 Answers1

0

There seems to be a workaround by not changing any code at all: The settings of the Release-build contain a checkbox if to use the .NET native toolbox for the build, which is enabled by default. By disabling that the build succeeds without any code change and is as fast as the Debug-build again. Before changing that, the Release-build took a lot longer as well.

Don't know what that means regarding actually calling native code, if that fails or not, because my app doesn't use those. I guess it would fail, depending on if it works in Debug or not. Additionally, I'm not sure if the Windows store accepts such a modified Release-build, but as UWP-apps aren't forced to use native code at all, I guess there's a good chance things are going to work.

Clipboard01 Clipboard02 Clipboard03

Thorsten Schöning
  • 3,501
  • 2
  • 25
  • 46