2

I have a project that is working well in debug mode, but not working at all in release mode.

The solution contains 3 projects

  • Shared project

  • windows phone 8.1 project

  • UWP project

here is the error output

 2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : System.InvalidOperationException: Unable to generate a temporary class (result=1).
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0012: The type 'Windows.UI.Xaml.Visibility' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows.Foundation.UniversalApiContract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0030: Cannot convert type 'Windows.UI.Xaml.Visibility' to 'Windows.UI.Xaml.Visibility [e:\MyApp\obj\x86\Release\ilc\in\WinMetadata\Windows.winmd]'
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : error CS0029: Cannot implicitly convert type 'Windows.UI.Xaml.Visibility [e:\MyApp\obj\x86\Release\ilc\in\WinMetadata\Windows.winmd]' to 'Windows.UI.Xaml.Visibility'
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : 
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.Compiler.Compile(String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Hashtable assemblies, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[] types, XmlMapping[] mappings, CompilerParameters parameters, String outputDir, String intermediateDir, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at System.Xml.Serialization.XmlSerializer.GenerateSerializer(Type[] types, String outputDir, String intermediateDir, List`1 wcfSerializers, Boolean loadAssembly)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error :    at SerializationAssemblyGenerator.Program.Main(String[] args)
2>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(887,5): error : Internal compiler error: One or more errors occurred.

The nuget packages I'm using are

    "GoogleAnalyticsSDK": "1.2.12",
    "HockeySDK.UWP": "4.0.0",
    "HtmlAgilityPack": "1.4.9",
    "Microsoft.ApplicationInsights": "1.0.0",
    "Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
    "Microsoft.ApplicationInsights.WindowsApps": "1.0.0",
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
    "MvvmLightLibs": "5.1.1",
    "Newtonsoft.Json": "8.0.3",
    "WriteableBitmapEx": "1.5.0"

Update

I tried to add the Windows.Foundation.UniversalApiContract manually, but got this

Update 2

After I have unchecked the Compile with .Net Native tool chain feature, it worked.

Any way to build it using the .net native tool chain ?

Community
  • 1
  • 1
Mostafa El-Abady
  • 618
  • 9
  • 25
  • 3
    *"You must add a reference to assembly 'Windows.Foundation.UniversalApiContract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'"* - Seems relevant. – IInspectable Jun 07 '16 at 13:22
  • No, this should be added automatically, check the updated question please. – Mostafa El-Abady Jun 08 '16 at 07:49
  • You can't trust the error messages you get after that first nasty mishap. Troubleshooting the .NET Native compiler is well beyond the scope of your question, it requires somebody that has access to your code and knows enough about the compiler to either find the bug in that compiler or suggest a workaround in your code. You can only find that somebody at Microsoft Support. – Hans Passant Jun 08 '16 at 08:53
  • A number of issues with .NET Native were addressed and a part of Visual Studio 2015 Update 2. Can you please confirm if you have the latest VS updates installed? You could also get in touch directly with the team at dotnetnative@microsoft.com and we would be happy to help (since it is likely that we won't be able to reproduce the issue with just these steps). – Unni Ravindranathan Jun 14 '16 at 03:17
  • Yes, I have the latest VS updates installed. – Mostafa El-Abady Jun 14 '16 at 08:58

1 Answers1

2

I also hit a very similar issue. I had a type, let's say Foo, referencing a winmd type Windows.UI.Xaml.Visibility, see below.

    public class Foo
    {
        public Windows.UI.Xaml.Visibility Visibility;
    }

I got the exact same error at compile time when I tried to serialize an instance of type Foo using XmlSerializer. It seems that .Net Native tools have problem with generating XmlSerializer for types like Foo.

Here's my workaround. I created my own Visibility type, MyVisibility, and changed the existing Visibility field to a get only property (so that XmlSerializer would not serialize the property).

    public class Foo
    {
        public Windows.UI.Xaml.Visibility Visibility
        {
            get
            {
                return (Visibility)myVisibility;
            }
        }

        public MyVisibility myVisibility;
    }

    public enum MyVisibility
    {
        Visible = 0,
        Collapsed = 1
    }

Here's my test code for serializing a Foo instance,

    public static void Test()
    {
        var foo = new Foo();
        foo.myVisibility = MyVisibility.Collapsed;            
        var serializer = new XmlSerializer(typeof(Foo));
        using (var stream = new MemoryStream())
        {
            serializer.Serialize(stream, foo);
            stream.Position = 0;
            var foo1 = (Foo)serializer.Deserialize(stream);
            Assert.True(foo.Visibility == foo1.Visibility);
        }
    }

Hope this helps.

X-Mao
  • 509
  • 3
  • 10