We have an application that implements a plug-in style architecture , using classes that implement MarhsalByRefObject,etc In some instances, an attempt to call a method from one AppDoman to another that creates an XPS document will throw the following
exception:
UnhandledException event raised in MapInfoPro.exe: System.NotSupportedException: The URI prefix is not recognized.
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at MS.Internal.WpfWebRequestHelper.CreateRequest(Uri uri)
at System.IO.Packaging.PackWebRequest.GetRequest(Boolean allowPseudoRequest)
at System.IO.Packaging.PackWebRequest.GetResponse()
at MS.Internal.WpfWebRequestHelper.GetResponseStream(WebRequest request, ContentType& contentType)
at System.Windows.Documents.PageContent._LoadPageImpl(Uri baseUri, Uri uriToLoad, FixedPage& fixedPage, Stream& pageStream)
at System.Windows.Documents.PageContentAsyncResult.Dispatch(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Win32.SafeNativeMethods.MessageBoxSystem(IntPtr hWnd, String text, String caption, Int32 type)
at Microsoft.Win32.SafeNativeMethods.MessageBox(IntPtr hWnd, String text, String caption, Int32 type)
at System.Diagnostics.AssertWrapper.ShowMessageBoxAssert(String stackTrace, String message, String detailMessage)
at System.Diagnostics.DefaultTraceListener.Fail(String message, String detailMessage)
at System.Diagnostics.TraceInternal.Fail(String message)
at MapInfoPro.App.StartApplication(String[] args) in c:\workdata\MiProTeamline\MiPro_Trunk_New12\Assems\MapInfoPro\App.xaml.cs:line 138
at MapInfoPro.MainClass.Main(String[] args) in c:\workdata\MiProTeamline\MiPro_Trunk_New12\Assems\MapInfoPro\App.xaml.cs:line 34
The perplexing part is, the method the problem seems to originate from is simple:
internal static IDocumentPaginatorSource GetInactiveContent(MemoryStream memStream, string memoryUri)
{
FixedDocumentSequence fixedDocSeq = null;
var packageUri = new Uri(memoryUri);
var package = Package.Open(memStream);
PackageStore.AddPackage(packageUri, package);
XpsDocument newDoc = null;
newDoc = new XpsDocument(package, CompressionOption.Fast, memoryUri);
fixedDocSeq = newDoc.GetFixedDocumentSequence();
DocumentReference docReference = fixedDocSeq.References.First();
FixedDocument doc = docReference.GetDocument(false);
var fixedPage = doc.Pages[0].GetPageRoot(true);
fixedPage.Background = Brushes.Transparent;
return fixedDocSeq;
}
And it looks like the call to 'new XpsDocument' is what's causing it. I say 'looks like' because removing that call eliminates the exception, but then we don't get the XpsDocument either. Attempting to try/catch the exception here doesn't work,as
it seems to bubble up through .NET and crash our application.
This appears to be some sort of timing issue, as it only happens under certain circumstances, mostly involving cross domain content from the application be closed/opened rapidly.
The URI's we are using are defined as:
_FrameControlUri = string.Format("memorystream://printstream{0}", Guid.NewGuid().ToString("N"));
In an attempt to keep them always unique, so it doesn't seem to be an issue with the URI itself, I'm suspicious that perhaps a package is somehow getting removed from the PackageStore and then the internal code .NET code to create the XPSDocument throws
an exception.
The application is very complex, and providing a small sample to reproduce the problem won't be possible. If you could help me understand that exception message , and possibly point me in the right direction to working around or preventing the problem
it would be greatly appreciated.
Thanks,
Chris