Hi all
Apologies for my first post being a support request - I hope it will be easy to answer. I wrote a C# Windows Service, fetched the
PDFsharp-MigraDoc-GDI package using NuGet, then added some logic based on one of the MigraDoc code samples. My program worked on my development machine, but when deployed to a live server, it fails
System.UnauthorizedAcessException. I added some diags, writing to Event Viewer logs at various points throughout the code, and this is the failing statement:-
Code:
MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
The user account that the Windows Service runs under has read/write permissions on the target folder where I am trying to save documents.
I noted that the MigraDoc and PDFsharp dlls are not saved in the GAC.
Can anyone advise a workaround please? I hope it is something simple.
Many thanks
This is the error stack.
Code:
Application: MyService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.UnauthorizedAccessException
at System.IO.__Error.WinIOError(Int32, System.String)
at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)
at System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean)
at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean)
at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding)
at MigraDoc.DocumentObjectModel.IO.DdlWriter..ctor(System.String)
at MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(MigraDoc.DocumentObjectModel.DocumentObject, System.String, Int32, Int32)
at MyService.exe.Create_Response_Files()
at MyService.exe.Process_Response()
at MyService.exe.Process_Request(System.String)
at MyService.exe.MyService.ReadCallback(System.IAsyncResult)
at System.Net.LazyAsyncResult.Complete(IntPtr)
at System.Net.ContextAwareResult.CompleteCallback(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Net.ContextAwareResult.Complete(IntPtr)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)