System.Windows.Markup.BamlRecordReader throws exception when loading application

The following is a stack trace of an error generated only on some Windows XP SP 2 machines where the application is installed. We have updated WIC on this machine, but continue to have this issue. I have installed this application on several different other machines with the same OS, and the application works. I am wondering if this machine is missing something. If someone could please comment on the following.

Machine OS: Windows XP SP 2

Using .NET Framework 3.0 (WPF)

Source: PresentationFramework

Message: Cannot create instance of 'MWindow' defined in assembly 'MyApp, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'MyApp;component/MWindow.xaml' Line 2 Position 5.

Stack Trace:

at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)

at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)

at System.Windows.Markup.BamlRecordReader.ThrowException(String message, Exception innerException)

at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)

at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)

at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)

at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)

at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)

at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)

at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()

at System.Windows.Markup.TreeBuilder.Parse()

at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)

at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)

at MS.Internal.AppModel.AppModelKnownContentFactory.BamlConverter(Stream stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)

at MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStream(Stream s, ContentType contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)

at System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest request, WebResponse response, Uri destinationUri, Object navState)

at System.Windows.Navigation.NavigationService.DoNavigate(Uri source, NavigationMode f, Object navState)

at System.Windows.Navigation.NavigateQueueItem.Dispatch(Object obj)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

at System.Windows.Threading.DispatcherOperation.InvokeImpl()

at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)

at System.Threading.ExecutionContext.runTryCode(Object userData)

at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

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, Boolean isSingleParameter)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

at System.Windows.Threading.Dispatcher.Run()

at System.Windows.Application.RunInternal(Window window)

at System.Windows.Application.Run(Window window)

at System.Windows.Application.Run()

at dm.SingleInstanceManager.OnStartup(StartupEventArgs e)

at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)

at dm.EntryPoint.Main(String[] args).

[6233 byte] By [AnonymousBNH] at [2008-1-8]
# 1

There was a problem creating MWindow. The problem could either be in the constructor for the MWindow class or in the XAML that is producing a runtime error. You might try looking at the exception and see if there are any inner exceptions that the parser wrapped. You can also enable first-chance exceptions in your debugger (In VS: Debug/Exceptions, check "Thrown" next to "Common Language Runtime Exceptions") to see what is throwing before the parser wraps the exception.

Ben

BenCarter-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Ben thank you for your quick response. I understand what you are explaining, but the issue that I'm having is not reproducible in my development environment. It seems to only happen on an external group of machines to whom I do not have access to run the debugger on. For that reason, in order to try to reproduce this issue. I took a lab machine reformated it with Windows XP, Installed SP2, installed .NET 2.0 and .NET 3.0. Finally, installed the WPF application on there and it ran without any problems. So, it leads me to suspect those external machines are missing something. I have checked with the users and they have everything that is required to run WPF applications.

1. Windows XP Sp2

2. Windows Imaging Component (The Latest one)

3. .NET 2.0 and .NET 3.0

Please tell me if I miss something, or if you have any other suggestions that can help me root cause the issue. I will try to see how can get more information on the exception that occurred.

AnonymousBNH at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

First look at MWindow.xaml Line 2 Position 5. Is that the open tag for MWindow or is something else there? If it's something else (like an image), then perhaps it is one of those external WPF dependencies you mention.

If it is the open tag for MWindow, then I would look at the MWindow's constructor. Do you have anything in there other than InitializeComponent? I would guess that something there throws an exception.

Another possibility to consider is that they are picking up an older version of your assembly somehow, and when we reflect in the parser, we get the old assembly instead of the new one.

Ben

BenCarter-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4

any update?

RobRelyea at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5

Unfortunately we were not able to reproduce the issue, but it seems to have something to do with the policy of a user profile in the operating system. Reason being, when we log in as a different user on the same machine the problem goes away. In other words, we are able to run the application in other user profiles, but not in this particular one.

AnonymousBNH at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6

I'll mark this an answered, so more people don't come try to answer it.

Please unmark if you have something we can try to investigate more.

There may be an innerexception that would be helpful.

Using Reflector, here is the code from CreateInstanceFromType, which may give you a clue to investigate...

internal object CreateInstanceFromType(Type type, short typeId, bool throwOnFail) { bool flag = true; BamlTypeInfoRecord typeInfoFromId = null; if (typeId >= 0) { typeInfoFromId = this.MapTable.GetTypeInfoFromId(typeId); if (typeInfoFromId != null) { flag = !typeInfoFromId.IsInternalType; } } if (flag) { if (!ReflectionHelper.IsPublicType(type)) { this.ThrowException(SRID.ParserNotMarkedPublic, type.Name); } } else if (!ReflectionHelper.IsInternalType(type)) { this.ThrowException(SRID.ParserNotAllowedInternalType, type.Name); } try { bool flag2 = EventTrace.IsEnabled(EventTrace.Flags.performance, EventTrace.Level.verbose); if (flag2) { EventTrace.EventProvider.TraceEvent(EventTrace.GuidFromId(EventTraceGuidId.PARSEREADERCREATEINSTANCEFROMTYPEGUID), 1); } if (TraceMarkup.IsEnabled) { TraceMarkup.Trace(TraceEventType.Start, TraceMarkup.CreateObject, type); } object obj2 = null; if (type != typeof(string)) { if (typeId < 0) { obj2 = this.MapTable.CreateKnownTypeFromId(typeId); } else if (flag) { obj2 = Activator.CreateInstance(type); } else { obj2 = XamlTypeMapper.CreateInternalInstance(this.ParserContext, type); if ((obj2 == null) && throwOnFail) { this.ThrowException(SRID.ParserNotAllowedInternalType, type.Name); } } } if (TraceMarkup.IsEnabled) { TraceMarkup.Trace(TraceEventType.Stop, TraceMarkup.CreateObject, type, obj2); } if (flag2) { EventTrace.EventProvider.TraceEvent(EventTrace.GuidFromId(EventTraceGuidId.PARSEREADERCREATEINSTANCEFROMTYPEGUID), 2, type.Name); } return obj2; } catch (MissingMethodException exception) { if (throwOnFail) { if ((this.ParentContext != null) && (this.ParentContext.ContextType == ReaderFlags.PropertyComplexDP)) { BamlAttributeInfoRecord parentObjectData = this.GetParentObjectData() as BamlAttributeInfoRecord; this.ThrowException(SRID.ParserNoDefaultPropConstructor, type.Name, parentObjectData.DP.Name); } else { this.ThrowException(SR.Get(SRID.ParserNoDefaultConstructor, new object[] { type.Name }), exception); } } return null; } catch (Exception exception2) { if (CriticalExceptions.IsCriticalException(exception2) || (exception2 is XamlParseException)) { throw; } this.ThrowException(SR.Get(SRID.ParserErrorCreatingInstance, new object[] { type.Name, type.Assembly.FullName }), exception2); return null; } }

Thanks, Rob

Rob Relyea | Program Manager, WPF & Xaml Language Team
robrelyea.com | /blog | /wpf | /xaml

RobRelyea at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified