I'm getting the most absurd error when calling Marshal.ThrowExceptionForHR(). My application performs certain FS operations and uses Marshal.ThrowExceptionForHR() to get the proper exceptions with the proper error messages.
However, in some tests we sometimes get the following error instead of the correct one.
'UnrelatedAssembly' is a real assembly in the application, but it isn't related in any way to my code, and isn't even referenced. (My code is on a lower level). It does use XmlSerializer. I've seen the detailed explanation about serializers Here, but it doesn't explain this behavior.
My only theory is that the XmlSerializer cache somehow operates in a multi-threaded environment and that the compilation that's meant for 'UnrelatedAssemby' is performed in my thread. That would require Marshal to also use XmlSerializer...
Can anyone confirm, correct, or otherwise explain this?
Thanks,
System.IO.FileNotFoundException: Could not load file or assembly 'UnrelatedAssembly.XmlSerializers' or one of its dependencies. The system cannot find the file specified. File name: 'UnrelatedAssembly.XmlSerializers'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark& stackMark)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at MyAssembly.Win32.ThrowLastError()
My code:
public static void ThrowLastError()
{
int err = Marshal.GetHRForLastWin32Error();
Marshal.ThrowExceptionForHR(err);
}