Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Produce build error when target framework is not netcoreapp #5361

Open
Braini01 opened this issue Feb 7, 2018 · 8 comments
Open

Produce build error when target framework is not netcoreapp #5361

Braini01 opened this issue Feb 7, 2018 · 8 comments

Comments

@Braini01
Copy link

Braini01 commented Feb 7, 2018

I want to make a .NET 4.7 console app a windows native exe and I was already successful in doing so with certain projects by adding the nuget package Microsoft.DotNet.ILCompiler and then calling dotnet publish -r win-x64 -f net47 -c Release xxx.csproj. But now I get a warning message like this:

EXEC : warning : Method '[MyLib]MyLib.MyType1'<System.__Canon>.MyMethod(string,bool)' will always throw because: [TEMPORARY EXCEPTION MESSAGE] FileLoadErrorGeneric: System.Private.Xml [C:...\MyNet47ConsoleApp.csproj]

I solved some of these errors before by just adding a reference to the missing assembly in the csproj file. But in this specific case System.Private.Xml is missing, which afaik is not part of the .Net Framework 4.7 and I am not sure how I reference it exactly.

@jkotas
Copy link
Member

jkotas commented Feb 8, 2018

this specific case System.Private.Xml is missing

The fix for this issue is included in https://github.com/dotnet/corert/pull/5329/files.

However, CoreRT will work well for .NET Core only. It won't work well for .NET Framework. It will happen to to work when your console app references surface that is common between the two, but it is easy to step outside of it by accident.

We should print error when the target framework is not netcoreapp.

Is there a reason why you cannot target .NET Core with your console app?

@jkotas jkotas changed the title How to fix FileLoadErrorGeneric warnings? Produce build error when target framework is not netcoreapp Feb 8, 2018
@Braini01
Copy link
Author

Braini01 commented Feb 8, 2018

Ah ok, I seemed to have missed the fact that net47 is not suited for CoreRT. CoreRT should have rang a bell though^^. My reason for using .Net Framework was System.Windows.Forms which provides the OpenFileDialog class but I can live without that. But even using .Net Core 2.0 I still have errors:

EXEC : warning : Method [System.Memory]System.MemoryExtensions.NonPortableCast<uint8,uint16>(ReadOnlySpan1) will always throw because: [TEMPORARY EXCEPTION MESSAGE] MissingMethod: System.ReadOnlySpan1<!!1> System.Span.NonPortableCast(System.ReadOnlySpan1<!!0>) [MyNetCoreApp.csproj]
EXEC : warning : Method [System.Memory]System.MemoryExtensions.NonPortableCast<uint8,uint32>(ReadOnlySpan1) will always throw because: [TEMPORARY EXCEPTION MESSAGE] MissingMethod: System.ReadOnlySpan1<!!1> System.Span.NonPortableCast(System.ReadOnlySpan1<!!0>) [MyNetCoreApp.csproj]
EXEC : warning : Method [System.Runtime.Extensions]System.Environment.ExpandEnvironmentVariablesCore(string) will always throw because: [TEMPORARY EXCEPTION MESSAGE] MissingMethod: Int32 System.Runtime.InteropServices.Marshal.GetHRForLastWin32Error() [MyNetCoreApp.csproj]
EXEC : warning : Method [S.P.Xml]System.Xml.Xsl.XslCompiledTransform.CompileQilToMsil(XsltSettings) will always throw because: [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.Reflection.Emit.TypeBuilder, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a [MyNetCoreApp.csproj]
EXEC : warning : Method [S.P.Xml]System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[],Type[],string) will always throw because: [TEMPORARY EXCEPTION MESSAGE] ClassLoadGeneral: System.Reflection.Emit.AssemblyBuilder, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a [MyNetCoreApp.csproj]

These are other error types (MissingMethod and ClassLoadGeneral) but seem to be sort of similar as I spot a .Private. again in System.Private.CoreLib. But the mentioned methods are not part of my own code btw.

@jkotas
Copy link
Member

jkotas commented Feb 8, 2018

These errors are issues with the framework that we are bundling with CoreRT:

@Braini01
Copy link
Author

Braini01 commented Feb 8, 2018

Could I circumvent these errors by not using certain functions (I use Reflection for example) or is it hard to figure out what exactly the cause is for those?

And btw, thx for the fast responses and even fixes. Very appreciated.

@jkotas
Copy link
Member

jkotas commented Feb 8, 2018

System.Xml.Xsl and System.Xml.Serialization errors are caused by something in your app is using types from System.Xml.Xsl and System.Xml.Serialization namespaces - either directly or indirectly. Does that help?

@Braini01
Copy link
Author

Braini01 commented Feb 8, 2018

It makes sense as my code is signing and serializing an XML. But as I get it, this is not supported currently?

@jkotas
Copy link
Member

jkotas commented Feb 8, 2018

Correct. Components that depend on Reflection.Emit are not supported by CoreRT currently.

@morganbr
Copy link
Contributor

The uapaot flavors of those assemblies might work. I haven't tried XSL, but Serialization should be able to fall back to reflection.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants