我的项目在调试模式下运行良好,但在发布模式下根本无法正常工作。
该解决方案包含3个项目
共享项目
windows phone 8.1项目
这是错误输出
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.
我正在使用的nuget包是
"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"
更新
我尝试手动添加Windows.Foundation.UniversalApiContract,但是得到了这个
更新2
在我取消选中使用.Net Native工具链的Compile功能之后,它就可以了。
使用.net本机工具链构建它的任何方法?
答案 0 :(得分:2)
我也遇到了一个非常类似的问题。我有一个类型,比方说Foo,引用winmd类型的Windows.UI.Xaml.Visibility,见下文。
public class Foo
{
public Windows.UI.Xaml.Visibility Visibility;
}
当我尝试使用XmlSerializer序列化Foo类型的实例时,我在编译时得到了完全相同的错误。似乎.Net Native工具在为Foo等类型生成XmlSerializer时遇到问题。
这是我的解决方法。我创建了自己的可见性类型MyVisibility,并将现有的可见性字段更改为 仅获取属性 (以便XmlSerializer不会序列化该属性)。
public class Foo
{
public Windows.UI.Xaml.Visibility Visibility
{
get
{
return (Visibility)myVisibility;
}
}
public MyVisibility myVisibility;
}
public enum MyVisibility
{
Visible = 0,
Collapsed = 1
}
这是我用于序列化Foo实例的测试代码,
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);
}
}
希望这有帮助。