Repository navigation
Description
I have a project that was created originally with blazor web assembly 3.2.
It used some more .net standard 2.0 projects to serialize a few classes from and to xml (also under .net standard 2.0).
I recently upgraded the blazor web app to .net 5.0 . (the projects under .net standard 2.0 remained as they were)
While everything on my development machines run smoothly when i deploy to iis I cant instantiate the xml serializer
[NotSupportedException] : "Parent does not have a default constructor. The default constructor must be explicitly defined."
The stack trace
at System.Reflection.Emit.TypeBuilder.DefineDefaultConstructor(MethodAttributes attributes)
blazor.webassembly.js:1 at System.Xml.Serialization.XmlSerializationILGen.GenerateBaseSerializer(String baseSerializer, String readerClass, String writerClass, CodeIdentifiers classes)
blazor.webassembly.js:1 at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace)
blazor.webassembly.js:1 at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location)
blazor.webassembly.js:1 at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace, String location)
blazor.webassembly.js:1 at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
blazor.webassembly.js:1 at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
blazor.webassembly.js:1 at System.Xml.Serialization.XmlSerializer..ctor(Type type)
blazor.webassembly.js:1 at PanasoftUtilities.XMLStatic.Create_ClassObject_From_XMLDeserialization[AADEBooksParam](String xml, String& Errormessage, Type[] ExtraTypes)
Source: System.Private.CoreLib
TargetSite: DefineDefaultConstructor
Of course there is no lack of default constructor anywhere. And anyway it works fine when running the site on visual studio and it worked fine under blazor 3.2 .net core 3.1.
I tried publishing the site using different combinations of x64 x86 and target runtime.
I ve being struggling with the issue for 2 days. I don't know what else to do.
Do you need me to upload the published artifacts so that you have a look?
Thanks for your advice.
Activity
javiercn commentedon Nov 19, 2020
@kostasxagoraris thanks for contacting us.
This is likely caused by the linker being more agressive in 5.0, you can customize the linker following the steps here
gonsalvg commentedon Nov 19, 2020
I was having the same issue, though on an asp.net hosted setup. Following @javiercn 's link I just decided to temporarily disable the crazy trimming by setting
<PublishTrimmed>false</PublishTrimmed>in my client project's propertygroup, which fixed this. Obviously hope to re-enable the feature soon as it seems nice :)I also found this post helpful https://devblogs.microsoft.com/dotnet/app-trimming-in-net-5/
kostasxagoraris commentedon Nov 19, 2020
I tried different things but i still havent resolved the issue (disabling trimming all the way is one of them ) I will try again tomorrow. I m sure i m doing something wrong because the error insists
kostasxagoraris commentedon Nov 20, 2020
I have disable trimming completely in my blazor webassembly client project and in the server project
like this i still get the same issue.
kostasxagoraris commentedon Nov 20, 2020
I also used this command
dotnet publish Panasoft.Web.MyData.Server.csproj -p:PublishTrimmed=false --self-contained --runtime win-x64 -c release
and the problem is still there. Very persistent!!
I m a bit frustrated What else can I do?
javiercn commentedon Nov 20, 2020
This seems to be an issue with the XML serializer running on WASM, the user disabled trimming and the problem still persisted
kostasxagoraris commentedon Nov 23, 2020
I also tried to copy the files from the build directory to a seperate web site on the same iis that i use for my development and i had the same exact issue.
kostasxagoraris commentedon Nov 24, 2020
Yet another similar issue
Trying to transform xml with xslt
Here is the working code .net code 3.1
And here is the error with .Net 5.0
danmoseley commentedon Nov 24, 2020
@eerhardt I wonder whether it would be useful to create a meta label to add to any trim safety issues.
eerhardt commentedon Nov 24, 2020
I've been using the
linkable-frameworklabel.The original issue is a duplicate of #41389 and will be resolved with #44772 once it gets approved.
The 2nd issue is a new one, it looks like the following code needs to be annotated correctly for the ILLinker to preserve the constructors correctly:
runtime/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs
Lines 135 to 159 in aebd598
Side-note: The ILLink warnings caught this as well:
runtime/src/libraries/System.Private.Xml/src/ILLink/ILLink.Suppressions.xml
Lines 130 to 141 in aebd598
eerhardt commentedon Nov 24, 2020
@kostasxagoraris - to try to get you unblocked on
net5.0, can you try the following?In your Blazor Client.csproj, add the following lines:
And then create a file named
LinkerWorkaround.xmlin your Blazor Client.csproj folder with the following contents:I tried this myself, and it worked for me. Let me know if it works for you. We will get this fixed in net6.0.
kostasxagoraris commentedon Nov 26, 2020
@eerhardt Thank you very much That solved all issues. Now it works smoothly!!