PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

MigraDoc throwing System.UnauthorizedAccessException
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3881
Page 1 of 1

Author:  RichardF [ Thu Nov 29, 2018 3:39 pm ]
Post subject:  MigraDoc throwing System.UnauthorizedAccessException

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*)

Author:  TH-Soft [ Thu Nov 29, 2018 4:12 pm ]
Post subject:  Re: MigraDoc throwing System.UnauthorizedAccessException

Hi!
RichardF wrote:
Can anyone advise a workaround please? I hope it is something simple.
It is something simple.
The file "MigraDoc.mdddl" is created for debugging purposes only. Remove the line and you're done.
Specify a folder with write access if you ever need that file for debugging.

Author:  RichardF [ Thu Nov 29, 2018 4:20 pm ]
Post subject:  Re: MigraDoc throwing System.UnauthorizedAccessException

Hi Thomas - that's great, all fixed. I am now at the next solution start-point :)

Many thanks

Richard

TH-Soft wrote:
Hi!
RichardF wrote:
Can anyone advise a workaround please? I hope it is something simple.
It is something simple.
The file "MigraDoc.mdddl" is created for debugging purposes only. Remove the line and you're done.
Specify a folder with write access if you ever need that file for debugging.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/