Serialization Assembly. Is it needed or not?

前端 未结 4 1576
梦如初夏
梦如初夏 2020-12-11 01:10

I have a .net 2.0 c# ClickOnce app and it connects to its data via Web Services. I\'ve been told that one way to potentially speed up the application is to generate a seria

相关标签:
4条回答
  • 2020-12-11 01:24

    According to Intellitrace, only the first time you XML-serialize a type, a FileNotFoundException is thrown and then caught. This means CLR expects to load an assembly containing all the XML-Serializers for that specific Assembly and when it's not found, a FileNotFoundException is thrown to signal the XmlSerializer: "Hey! Generate the darn assembly!" and this is what happens during that "Catch" and then the previously not found file exists.

    I've read somewhere that using try-catch for logic is a bad exercise. IDK why Microsoft has used this approach...

    0 讨论(0)
  • 2020-12-11 01:26

    It is really asking "Shall I pre-generate the serialization assemblies and include it in the deployed project or shall I fall back on the default of generating the assemblies on the fly?" Generally that won't hurt too much after the first hit perf-wise. Where it can play in is that the serialization assemblies are generated in %SYSTEMROOT%\TEMP. Which, in some cases, the process can't access, leading to fatal exceptions in most cases.

    0 讨论(0)
  • 2020-12-11 01:36

    This is not relevant to your situation, but there's another good reason for pre-generating the serialization assembly - it's necessary when hosting your code in SQL Server (i.e. SQLCLR). SQL Server doesn't allow these assemblies to be generated dynamically, so your serialization code would fail inside SQL Server.

    0 讨论(0)
  • 2020-12-11 01:38

    In most cases, you aren't likely to see a huge benefit from this, especially if you keep the app open for a while. Pre-generating a serialization assembly mainly helps the first time (in an exe lifetime) that you serialize a specific type as xml.

    0 讨论(0)
提交回复
热议问题