Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
I get the following exception while creating XmlSerializer object on some system, it's working as expected on others.
Please provide suggestions or pointers.

System.Runtime.InteropServices.COMException (0xD0000003): Exception from HRESULT: 0xD0000003
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.CodeDom.Compiler.FileIntegrity.MarkAsTrusted(SafeFileHandle safeFileHandle)
   at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
   at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)
   at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)
   at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
   at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
   at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
   at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)


What I have tried:

I tried to reproduce the issue with untrusted DLL, but it's working as expected.
Posted
Updated 27-Oct-23 5:26am
v2
Comments
Richard Deeming 26-Oct-23 5:03am    
There doesn't seem to be any decent documentation of HRESULT 0xD0000003. The only vaguely-relevant article I could find suggests it might be your antivirus interfering with the dynamic assembly compilation used by the XmlSerializer class.

Try using sgen to precompile the serialization assemblies to see if that helps:
XML Serializer Generator Tool (Sgen.exe) - .NET | Microsoft Learn[^]
Dnyaneshwar Patil 27-Oct-23 1:32am    
Tried disabling antivirus still issue reproducible. Looks like issue is showing up after installation of .Net 4.8.1 on some system.

1 solution

System.Runtime.InteropServices.COMException suggests external DLL issue. There may be an old DLL on some systems. What that DLL is I have no idea from the error message.

Try making sure that the latest OS updates are installed along with the .Net Framework version. I would go as far as to manually download the .Net SDK and manually install it on the systems with the issue.

The other thing that you could try is running your installed app as an administrator. If this resolves it, then one of the DLLs being used has an elevated privilege above the user trying to run your app. Check privileges for all of then installed DLLs for your app &/or manually set the privileges for the user(s).
 
Share this answer
 
v2
Comments
Dnyaneshwar Patil 27-Oct-23 1:30am    
Tried this but looks like the issue reproducible after installation of .Net 4.8.1 on some system.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900