I'm having this error when running my C# .net 4.5 windows forms project from IDE or exe, I have no clear or fixed scenario, and I can't find a clue in the exception that is being thrown. I want to know how to get the source of error and fix it, or at least handle it in a way that does not make the exe crashed!
Below are the details of the exception:
Message:
Exception has been thrown by the target of an invocation.
Inner Exception Message:
Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
Inner Exception Stack Trace:
at
System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at
System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at
System.Windows.Forms.Control.DefWndProc(Message& m) at
System.Windows.Forms.Control.WndProc(Message& m) at
System.Windows.Forms.TextBoxBase.WndProc(Message& m) at
System.Windows.Forms.RichTextBox.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at
System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd,
Int32 msg, Int32 wParam, EDITSTREAM lParam) at
System.Windows.Forms.RichTextBox.StreamIn(Stream data, Int32 flags)
at System.Windows.Forms.RichTextBox.StreamIn(String str, Int32 flags)
at System.Windows.Forms.RichTextBox.set_Rtf(String value) at
TragTask.UserControls.CommentControl.SetCommentInfo() in
C:\TFS\Tragging\Tragging
Solutions\TragTask\TragTask\UserControls\CommentControl.cs:line 76
at
TragTask.UserControls.CommentControl.set_Comment(TaskMilestoneTimerAndComment
value) in C:\TFS\Tragging\Tragging
Solutions\TragTask\TragTask\UserControls\CommentControl.cs:line 49
at TragTask.Forms.frmTaskDetails.d__24.MoveNext()
in C:\TFS\Tragging\Tragging
Solutions\TragTask\TragTask\Forms\frmTaskDetails.cs:line 339 at
System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(Object
stateMachine) 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.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
at
System.Runtime.CompilerServices.TaskAwaiter.<>c__DisplayClass11_0.b__0()
at
System.Runtime.CompilerServices.AsyncMethodBuilderCore.ContinuationWrapper.Invoke()
at
System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.<>c.<.cctor>b__8_0(Object
state)
TargetSite
{System.Object InvokeMethod(System.Object,
System.Object[], System.Signature, Boolean)}
Target Site, Declaring Types:
{Name = "RuntimeMethodHandle" FullName = "System.RuntimeMethodHandle"}
Stack Trace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]
arguments, Signature sig, Boolean constructor) at
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object[] parameters, Object[] arguments) at
System.Delegate.DynamicInvokeImpl(Object[] args) at
System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry
tme) at
System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
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.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry
tme) at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam) at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
dwComponentID, Int32 reason, Int32 pvLoopData) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context) at
System.Windows.Forms.Application.Run() at TragTask.Program.Main()
Update
After C.Evenhuis pointed out that this has to do with CommentControl.SetCommentInfo method, I thought it would be needed to add this method in my question (note that tb_comment is a RichTextBox control):
public bool SetCommentInfo()
{
try
{
this.SuspendLayout();
lbl_user.Text = "userName";
lbl_dateTime.Text = mComment.DateTimeAdded.ToString("dd/MM/yyyy HH:mm:ss");
if (mComment.Comment.TrimStart().StartsWith("{\\rtf1", StringComparison.Ordinal))
{
tb_comment.Clear();
tb_comment.Text = "";
tb_comment.Rtf = mComment.Comment;
}
else
tb_comment.Text = mComment.Comment;
return true;
}
catch (Exception ex)
{
Utils.Global.ErrorLog("SetCommentInfo", ex, true);
return false;
}
finally
{
this.ResumeLayout();
}
}
MSDN:
Corrupted process state exceptions are exceptions that indicate that the state of a process has been corrupted. It's not recommended to execute your application in this state.
By default, the common language runtime (CLR) does not deliver these exceptions to managed code, and the try/catch blocks (and other exception-handling clauses) are not invoked for them. If you are absolutely sure that you want to maintain your handling of these exceptions, you must apply the HandleProcessCorruptedStateExceptionsAttribute attribute to the method whose exception-handling clauses you want to execute. The CLR delivers the corrupted process state exception to applicable exception clauses only in methods that have both the HandleProcessCorruptedStateExceptionsAttribute and SecurityCriticalAttribute attributes.
You can also add the to your application's configuration file. This will ensure that corrupted state exceptions are delivered to your exception handlers without the HandleProcessCorruptedStateExceptionsAttribute or SecurityCriticalAttribute attribute. This configuration element has no effect on applications that were compiled in versions previous to the .NET Framework 4 but are running in the .NET Framework 4 or later; corrupted state exceptions will continue to be delivered for those applications. The HandleProcessCorruptedStateExceptionsAttribute attribute is ignored when it is encountered in partially trusted or transparent code, because a trusted host should not allow an untrusted add-in to catch and ignore these serious exceptions.
Related
We experience following crash at random moments in our WPF application:
Invalid index at MS.Win32.UnsafeNativeMethods.GetWindowText(HandleRef hWnd, StringBuilder lpString, Int32 nMaxCount)
at System.Windows.Automation.Peers.WindowAutomationPeer.GetNameCore()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.ContextLayoutManager.fireAutomationEvents()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
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 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext 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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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 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.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
Most of the time the crash occurs on any call to "ShowDialog()" in the WPF code, sometimes also on other calls (unclear which exactly, the stack trace just mentions the top-level "Application.Run()")
The problem starts occurring randomly after having accessed some javascript code in a CefSharp embedded browser component, which adds WebRTC streaming functionality to the WPF application. The crashes stopped occurring as soon as we replaced the CefSharp component with Microsofts WebView2 component.
On a few occasions in the past we encountered the exact same random crash when our WPF application was running alongside 2 other third party applications :
a "TabletInputService", part of Smart Technologies whiteboard software
a screen capture driver ("VHScrCap" of Split Media Labs)
At that moment we found that the crash even occurred in a dummy WPF test application which contained nothing but 1 "ShowDialog()" call. This lead us to the conclusion that we could change nothing in our WPF application code to avoid the crashes. Only "solution" was to replace above screen capture driver with the DirectShow "screen-capture-recorder"
My question is : what could be the root cause of this window handle corruption, and what could we do to avoid the resulting crashes in a WPF application?
I hope I found the cause of this issue. I again encountered the same crash, but again under different conditions: after calling VideoCapturer.EnumerateDevices() on the OpenTok.NET Nuget library, the crash started occurring when expanding any combobox in any WPF modal dialog.
Now it looks like the instability is caused by not specifying the Title property of a WPF window. In our application most of the dialogs are headerless (WindowStyle="None"), as we design our own window headers, so setting the Title property is unnecessary/irrelevant. This must confuse the Win32 API call "GetWindowText()", resulting in a nasty crash. Seems like a serious WindowOS/WPF bug to me.
After scanning our full application source code and specifying a (dummy) Title for each and every dialog, the crash stopped occurring (at least for now).
I have now also reviewed the code of the "dummy WPF test application" mentioned earlier, which could reproducibly trigger the crash under certain conditions. And indeed, the code was :
Window dummy = new Window();
dummy.ShowDialog();
Today I no longer can reproduce the error condition (triggered by third party applications) but it now seems likely that adding dummy.Title = 'Dummy'; to the test code above would have avoided the crash.
I have just today started seeing this Exception out in the wild on application launch with an app that has been in production for 3 years.
System.TypeInitializationException: The type initializer for 'MS.Win32.Penimc.UnsafeNativeMethods' threw an exception. ---> System.Runtime.InteropServices.COMException: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
at MS.Win32.Penimc.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at MS.Win32.Penimc.UnsafeNativeMethods.CreatePimcManager()
at MS.Win32.Penimc.UnsafeNativeMethods..cctor()
--- End of inner exception stack trace ---
at MS.Win32.Penimc.UnsafeNativeMethods.CreateResetEvent(IntPtr& handle)
at System.Windows.Input.PenThreadWorker..ctor()
at System.Windows.Input.PenThreadPool.GetPenThreadForPenContextHelper(PenContext penContext)
at System.Windows.Input.PenThreadPool.GetPenThreadForPenContext(PenContext penContext)
at System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTabletsImpl()
at System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTablets()
at System.Windows.Input.StylusWisp.WispTabletDeviceCollection..ctor()
at System.Windows.Input.StylusWisp.WispLogic.get_WispTabletDevices()
at System.Windows.Input.StylusWisp.WispLogic.RegisterHwndForInput(InputManager inputManager, PresentationSource inputSource)
at System.Windows.Interop.HwndStylusInputProvider..ctor(HwndSource source)
at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
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 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext 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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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 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.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at APSSSentinel.App.Main()
Apparently, some developers using VS2017 who got a Windows update that installed .NET 4.7 have been getting this crash as well, it appears the recommended workaround for now is to turn touch support off.
https://developercommunity.visualstudio.com/content/problem/55303/visual-studio-may-terminate-unexpectedly-when-runn.html
With my application, this is not ideal. Has anyone else run into this, and found any other sort of workaround?
Update: Microsoft has now fixed this problem in a manual update (as noted by Jürgen), personally I will stick with the workaround until the fix is in the automatic update because it would be a lot of work to make every user install a manual update.
This is obviously a bug in .Net 4.7 that affects Windows 7 and 8/8.1 systems that have a touch input device. Therefore one can hope that Microsoft addresses this in a future update. Meanwhile the only way to retain full functionality is by uninstalling and hiding the update.
Other option is disabling the stylys and touch support either in app.config (like in your link) or in the code if the app is compiled with 4.6 or newer. You didn't specify why that is not ideal but I assume those features are needed? Notice that the disabling doesn't mean that every app is unusable with touch devices, but rather that they only use features that are accessible with a mouse. Update: Apparently touch device users without a mouse will have trouble using UI that requires scrolling.
Here's the code examples for those who come here seeking quick fix:
In App.config (works with apps compiled with any framework version)
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" />
</runtime>
</configuration>
In code (when compiled with .Net Framework >= 4.6)
protected override void OnStartup(StartupEventArgs e)
{
AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport", true);
base.OnStartup(e);
}
Microsoft has fixed the issue with .NET 4.7 meanwhile, see
https://support.microsoft.com/en-US/help/4033488/comexception-error-from-wpf-applications-after-the-net-framework-4-7-i
I'm getting a null reference in the PresentationFramework on my LifeShaping filtering:
The stack trace isn't giving me much clue:
at System.Windows.Data.ListCollectionView.RestoreLiveShaping()
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext 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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.ShowDialog()
at MVVMSeaCores.AppWindowManager.ShowDialog(Object rootModel, Object context, IDictionary`2 settings)
That last line is the dialog call that shows the UX that holds the checkbox bound to ShowOnGraph.
I'm setting the live-shaping like this, based off a boolean property "ShowOnGraph":
KPIBarsView = new CollectionViewSource { Source = KPIBars }.View;
KPIBarsView.Filter = FilterBars;
//grouping
if (KPIBarsView != null && KPIBarsView.CanGroup == true)
{
KPIBarsView.GroupDescriptions.Clear();
KPIBarsView.GroupDescriptions.Add(new PropertyGroupDescription("KPIViewModel.ContextViewModel"));
}
//Live Filtering
ICollectionViewLiveShaping KPIBarsViewLiveShaping = KPIBarsView as ICollectionViewLiveShaping;
if (KPIBarsViewLiveShaping.CanChangeLiveFiltering)
{
KPIBarsViewLiveShaping.LiveFilteringProperties.Add("ShowOnGraph");
KPIBarsViewLiveShaping.IsLiveFiltering = true;
}
Items are filtered as I'd expect when ShowOnGraphis set to false. However, as soon as I try and unfilter anything with ShowOnGraph=true I get this exception.
This is not a duplicate of "What's a null reference exception". I know what a null reference exception is. But in this case, the null reference is in the Presentation Framework, in System.Windows.Data. I've got no idea what's null, why (the list doesn't contain any null entries, the filter Property is a bool and cannot be null).
The null object isn't in my code, and isn't available for me to debug. All I get in the debugger is where in the dispatch it was when this occured. In one case, it's in the dialog that contains the list where I'm setting it to true:
There's nothing null.
I'll just make a button to set a ShowOnGraph=false, and see where the exception occurs there.
Edit: Yep, it occurs "nowhere". Just opens up on a blank "Break mode" page with no content or indication of where the error occurred.
johnDisplayClass's comment is very helpful.
Something that worked for me: was if i also kept a member reference to each new CollectionViewSource as well as its CollectionView. This kept my live shaping and filtering working. Just this alone solved the same null ref that the OP was experiencing.
Another way to prevent this null exception is to set IsLiveSorting / IsLiveGrouping / IsLiveFiltering to false before the CollectionViewSource or CollectionView been garbage collected.
Found a solution!
I was creating the view directly (rather than using the default view, because I in had two views driven from this collection:
KPIBarsView = new CollectionViewSource { Source = KPIBars }.View;
Which I did after reading this: http://social.technet.microsoft.com/wiki/contents/articles/26673.wpf-collectionview-tips.aspx
and the following SA questions:
WPF Multiple CollectionView with different filters on same collection
WPF CollectionViewSource Multiple Views?
However, I tried just creating a new collection, populating it with the same items and using:
KPIBarsView = CollectionViewSource.GetDefaultView(KPIBars);
solved the problem. Hope this is helpful for anyone else who stumbles upon it.
What I recommend is that you set yourself up to debug the Microsoft dll's from within your solution
https://msdn.microsoft.com/en-us/library/cc667410.aspx
Then make sure your debug settings have all of the possible exception types checked, then when you run your app again and break on the exception, you'll get a full stack trace that could help you work out the isse.
New to Power BI, but downloaded Power BI Desktop. I connected it to my Postgres Database and all was looking good. I am pulling data and able to start building relationships & reports.
I saw this curious bar appear though:
I clicked it and it looked like it was connecting to the DB and pulling data again from all my tables. A the end I see an error notice with this warning:
Failed to save modifications to the Server. Error returned: 'The base version must not be negative when impact is requested for a transaction.'.
It let's me "Copy Details" and I see the full stack trace:
Error Message:
Failed to save modifications to the Server. Error returned: 'The base version must not be negative when impact is requested for a transaction.
'.
Stack Trace:
Microsoft.AnalysisServices.OperationException: Failed to save modifications to the Server. Error returned: 'The base version must not be negative when impact is requested for a transaction.
'.
Server stack trace:
at Microsoft.AnalysisServices.Tabular.Model.SaveChanges(SaveOptions saveOptions)
at Microsoft.PowerBI.Client.Windows.AnalysisServices.Relationships.RelationshipDetectionFast.Detect(HashSet`1 newTableColumnPairs, CancellationToken cancellationToken, RelationshipDetectionProgress progress)
at Microsoft.PowerBI.Client.Windows.AnalysisServices.Relationships.RelationshipManager.AutodetectRelationships(RelationshipDetectionTypes detectionTypes, HashSet`1 newTableColumnPairs, RelationshipDetectionProgress progress)
at Microsoft.PowerBI.Client.Windows.Modeling.RelationshipLoader.<>c__DisplayClassf.<>c__DisplayClass11.<AutodetectRelationships>b__e()
at Microsoft.PowerBI.Client.Windows.AnalysisServices.Relationships.RelationshipManagerHelper.ExecuteAndCommitChanges(IRelationshipManager manager, Action action)
at Microsoft.PowerBI.Client.Telemetry.PowerBITelemetryService.LogTimedAction(TelemetryUserActionId userActionId, Action`1 action)
at Microsoft.PowerBI.Client.Windows.Modeling.RelationshipLoader.DetectAndImportRelationships(SynchronizationContext uiThreadContext, IAnalysisServicesLoadToken loadToken, IEnumerable`1 loadInputs, IAnalysisServicesLoadContext loadContext, Report report, IExtendedModelChangeScope modelChangeScope, List`1 newTableColumnPairs, Action relationshipAutodetectStartCallback)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.CreateRelationships(IAnalysisServicesLoadContext loadContext, IExtendedModelChangeScope modelChangeScope, List`1 newTableColumnPairs, Action relationshipAutodetectStartCallback)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.ProcessLoadInputs(IExtendedModelChangeScope modelChangeScope, Action relationshipAutodetectStartCallback)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.<>c__DisplayClass7.<PerformLoadInternal>b__5(IExtendedModelChangeScope modelChangeScope)
at Microsoft.PowerBI.Client.Windows.Modeling.AsyncModelAuthoringService.<>c__DisplayClass9.<RunExtendedModelChangeAsync>b__7(Task`1 t)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
Exception rethrown at [0]:
at Microsoft.PowerBI.Client.Windows.Utilities.TaskExtensions.WaitAndUnpackException(Task task)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.PerformLoadInternal(Action relationshipAutodetectStartCallback)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.PerformLoad(Action relationshipAutodetectStartCallback)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.<>c__DisplayClass1.<LoadTablesAsync>b__0(Object state)
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
Invocation Stack Trace:
at Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
at Microsoft.Mashup.Client.ClientShared.StackTraceInfo..ctor(String exceptionStackTrace, String invocationStackTrace)
at Microsoft.Mashup.Client.ClientShared.UnexpectedExceptionHandler.<>c__DisplayClass1.<HandleException>b__0()
at Microsoft.Mashup.Host.Document.SynchronizationContextExtensions.<>c__DisplayClass3.<SendAndMarshalExceptions>b__0(Object null)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
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.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at Microsoft.Mashup.Client.ClientShared.WindowManager.ShowDialog[T](T form, IWin32Window owner)
at Microsoft.Mashup.Client.ClientShared.Ux.FloatingDialog.FloatingDialog.ShowDialog(IWin32Window owner, Nullable`1 showTimeout)
at Microsoft.PowerBI.Client.Windows.FloatingDialog.KoLoadToReportDialog.StartEvaluationAndShowDialog(IEnumerable`1 queriesToLoad, Nullable`1 showTimeout, Boolean requireFullDataRefresh)
at Microsoft.PowerBI.Client.Windows.FloatingDialog.KoLoadToReportDialog.TryShowDialogForQueries(Report report, IWin32Window ownerWindow, WindowsHost windowsHost, IEnumerable`1 queriesToLoad, LocalizedString title, Boolean requireFullDataRefresh)
at Microsoft.PowerBI.Client.Windows.HtmlControls.ReportView.ReportCanvasProxyHtmlControlAsync.<LoadQueriesToReportFromInfoBar>b__6()
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
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.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at Microsoft.Mashup.Client.ClientShared.WindowManager.ShowDialog[T](T form, IWin32Window owner)
at Microsoft.PowerBI.Client.Program.<>c__DisplayClassb.<Main>b__0()
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
at Microsoft.PowerBI.Client.Program.Main(String[] args)
ModelChangeStartingStackTrace
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at Microsoft.PowerBI.Client.Windows.Modeling.AsyncModelAuthoringService.RunExtendedModelChangeAsync(Action`1 extendedModelChange, CancellationToken cancellationToken, Boolean blockUI)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.PerformLoadInternal(Action relationshipAutodetectStartCallback)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.PerformLoad(Action relationshipAutodetectStartCallback)
at Microsoft.PowerBI.Client.Windows.Modeling.PowerQueryToModelLoader.<>c__DisplayClass1.<LoadTablesAsync>b__0(Object state)
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
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.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
What does the error message mean? I don't know what data failed to be written out.
Also, what Server did it try to write to? Did it fail to write to a local internal database of Power BI or did it try to write out to my remote connected postgres database?
Older post I know, but I just got this error message and was able to get around it.
Searching around, I found this post from a user named jagatho that says
It has to do with the auto detection of relationships.
If I remove the column that would make sense that Power BI would predict having a relationship between tables and added a new one with the same name with null values in two PowerQuery steps, then I can load the data.After the initial load I can remove the two steps and everything works, because it only tries to detect relationships on the initial load.
While I wasn't able to find the column(s) causing the trouble, in Power BI Desktop (Version: 2.64.5285.661 64-bit (November 2018)), File | Options and settings | Options | CURRENT FILE | Data Load, unchecking "Autodetect new relationships after data is loaded" solved the problem for me.
I am stuck with this error: while trying to use an old DLL in .Net Framework 4.0
If I change project target type to 3.5 then no error appears.
The strange is that all this happen Only while running inside VS 2010. If I run the executable from Windows Explorer, no problem occurs in 3.5 and 4.0.
Seems like some bug in vshost? VS 2010 Express, or .net framework?
UPDATE: This BUG only happen on WPF Standalone Application, if a change it to XBAP WPF I can use the dll without bigger problems, only a message telling it could no stop debugging.
I will leave this question open here, waiting to see if there is some progress on the connect.microsoft.com about this ticket.
Is there some way to make my .net4 app.config load this specific dll(CobreBemX.dll) using the .net 3.5 ?
I think this is some bug then i submitted it to https://connect.microsoft.com/VisualStudio/feedback/details/636697/comexception-was-unhandled-catastrophic-failure
Here is the code where it throws that COMException:
//Cria instância do objeto CobreBemX
CobreBemX.ContaCorrente _CobreBemX = new CobreBemX.ContaCorrenteClass();
//Monta arquivo de licença de teste para banco 001 carteira 18
_CobreBemX.ArquivoLicenca = #"C:\CobreBemX\Exemplos\Licencas\237-09.conf"; // THIS LINES CAUSES THE PROBLEM ON .NET 4.0 IF I CHANGE TARGET FRAMEWORK TO 3.5 NO PROBLEM HAPPENS
This is the stack trace:
System.Runtime.InteropServices.COMException was unhandled
Message=Falha catastrófica
Source=CobreBemX.ContaCorrente
ErrorCode=-2147418113
StackTrace:
at CobreBemX.ContaCorrenteClass.set_ArquivoLicenca(String Value)
at EmissorBoletosWindows.MainWindow.button1_Click(Object sender, RoutedEventArgs e) in C:\inetpub\wwwroot\CRM\Cobranca\EmissorBoletosWindows\EmissorBoletosWindows\MainWindow.xaml.cs:line 90
at EmissorBoletosWindows.MainWindow.Window_Loaded(Object sender, RoutedEventArgs e) in C:\inetpub\wwwroot\CRM\Cobranca\EmissorBoletosWindows\EmissorBoletosWindows\MainWindow.xaml.cs:line 39
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at MS.Internal.LoadedOrUnloadedOperation.DoWork()
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
at System.Windows.Interop.HwndTarget.OnResize()
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(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.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Window.ShowHelper(Object booleanBox)
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.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, Boolean ignoreSyncCtx)
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.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
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.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at EmissorBoletosWindows.App.Main() in C:\inetpub\wwwroot\CRM\Cobranca\EmissorBoletosWindows\EmissorBoletosWindows\obj\x86\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
If you examine the top of the stack, the method suggests the library is performing some software licensing processing. My guess (and it is a guess) is that the library is using the executable's name and path to locate the license and, because the application is running through VSHost, this is failing causing an error which is expressed as a COM exception.
The fact it works fine outside of VSHost would lend weight to this. You could use a tool such as FileMon to possibly see where it is tripping up.
For now this has no solution other than use XBAP