Attempted to read or write protected memory - wpf

I am trying to learn WPF. I am following along with a book(WPF in 24 hours) and occasionally I get the following error:
Attempted to read or write protected memory. This is often an indication that other memory has been corrupted.
When I click "OK" the application continues to run as if nothing is wrong.So far I have worked with XAML only and have not entered any other code. The examples that I have found so far in SO and google reference specific code issues. Any shove in the right direction would be appreciated.
Oh...I am using VS2008 Pro

I had this when declaring a Style without specifying the TargetType. I cannot remember if that was in WPF or Silverlight2 though.

Old question, but in case it helps someone...
I had this error as a build error in a XAML file of a Template10, MVVM UWP app.
The reason appears to be because I was referencing a ViewModel that is in a separate .dll.
Moved the referenced ViewModel into the app, the build error goes away.

Related

LiveCharts GeoMap WPF

I am trying to replicate this LiveCharts GeoMap in WPF but having an issue with the source file of my xml map :-
https://lvcharts.net/App/examples/v1/wpf/GeoHeatMap
I can produce it fine under WinForms but need to create a working version under WPF, if anyone can assist or point me in the right direction, I’m sure it’s something obvious that I’m missing?
The error I get states that the source path for my xml file doesn’t exist, when it clearly does.
If I follow the example, I create a user control, copy in the xaml plus the code behind, as per the website, then in my main window xaml, make reference to the user control. It’s at this point that it can’t load my main window as it can’t find the source file that I have referenced in my user control. In winforms I can reference it using source=#“c:\temp\world.xml” in code behind but cant do that in the xaml either. Where am I going wrong! Thanks
I had the same issue. It seems as if the NuGet package is outdated (2017).
Try to clone the LiveCharts repository and build it yourself.
In the properties of the XML file:
set Compile Action to none
In the Copy to directory:
set it to Copy Always
My Visual Studio is in Portuguese, but I think you'll get the idea.
If you're interested, there are detailed maps for each country/region; go to https://github.com/Live-Charts/Live-Maps.

System.Runtime.RemotingException in simple XAML file

I have a WPF application which is giving me a very very annoying error
System.Runtime.Remoting.RemotingException
[12068] Designer process terminated unexpectedly!
The number between [] changes each time
The XAML is very simple
<UserControl x:Class="STC.Reports.ReportGenerator.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</UserControl>
This has wasted me hours and hours
Does anyone know anything that could help?
I cant get any more information than that above
Even though I have told VS to break on these Exceptions it doesnt
I have also tried to attach another VS and that makes no difference
I have repaired my installation of VS (2012 Professional)
I have also updated to Update 3
This is even happening when I create a brand new WPF application
Everything seems fine initially, then VS just hangs and the remoting error occurs
Paul
What kind of message are You getting?
If it is a Messagebox when You try to use designer - it is a known issue since VS2010 as far as I remember. It is frequently caused by a video card or its driver, so the easiest way is trying to update your video driver or use some older version. Sometimes that help.
The other way is not to use built-in designer. As for me, I wite pure xaml and it seems to be more convenient and faster way of development. Or, if You like visual UI - You may use Blend. AFAIK it is a part of VS2012 now.
I had this error occur for all windows/controls in a project, even if they were brand new empty windows. I had a markup extension causing a design-time exception (with no indication of this from Visual Studio) and I would get this designer error if I used the markup extension in any project resource dictionaries.
Old post but might be useful for future developers who run into this kind of problem.
I had this exact behaviour. Turned out to be a problem related to my viewmodel. At runtime everything works, but at design time VS will try to load the viewmodel standalone and things got haywire. My viewmodel depended on some global object which I created elsewhere at application startup. Loading the viewmodel standalone creates a exception since the global object was missing.
Quite easy to detect actualy. Just test your viewmodel by instantiating it yourself from code. If it fails VS won't be able to run the designer as well and as you see VS unfortunately won't tell you what happened.

WPF: VS2012 designer shows "The component 'XXX' does not have a resource identified by the URI YYY"

As the title suggests, this error is thrown by the designer, which means the designer can't display my UserControl correctly which in turn means I can't navigate smoothly from element to element in this UserControl to make modification. Really annoying.
XXX is the name of my UserControl, while the URI YYY is actually XXX's path. So I don't know understand it can't find itself as resource. I googled this error, but most of them happened in the runtime. In my case it doesn't happen at all when I execute it. The description of this error is really not explanatory enough, because I am not sure who in the CLR is loading the file itself as a resource.
Another thing might be worth mentioning is, this error only happens after I build my application project, which the error UserControl resides in. After I click to clean the project, the designer can display the whole stuff (but obviously I can't clean the project every time before I make any change, since the building takes time)
It is possible that the control's .g.cs or .g.i.cs file has been corrupted. Try to clean, close visual studio and restart it. I think that helped for me in several cases especially when I copy paste controls from one solution to another.
Just delete subfolders in
%LOCALAPPDATA%\Microsoft\VisualStudio\12.0\Designer\ShadowCache
If you refactor a UserControl down a lower level project that the UserControl was previously referencing then you will see this error.
Removing the assembly reference from the namespace fixes the issue.
<UserControl xmlns:ui="clr-namespace:MyCompany.Core.UI;assembly=MyCompany.Core.UI"
should be
<UserControl xmlns:ui="clr-namespace:MyCompany.Core.UI"
The designer is not smart enough to highlight this.
I ran into the same issue, it compiled and ran fine, but the XAML editor/Designer complained. In my case, I found the solution to be that my user control was declared within a namespace in the XAML (x:Class="myNamespace.myUserControl") but not in the code behind. Adding the namespace declaration in the code behind solved my issue.
There is a possibility to debug Visual Studio Designer in the second attached Visual Studio.
See How to troubleshoot and debug Visual Studio design mode errors for details.
To display the UserControl, the designer has to instantiate the user control. Look for possible Null Reference Exceptions.
In my case the user control had an NRE due to a dependency not being injected. I added handling for the NRE and no more issue.

Why is Expression Blend 4 not finding resources that are in a global Resource Library

For some reason with this WPF project, I am getting the following exception in Blend:
This happens when one UserControl is inside another UserControl or Window. ItemBorder is a style that exists in a Resource Library linked to the application XAML file. It doesn't matter where I move this resource or its library. Even if I put it directly into the UserControl that is using it, I get this exception. Only when I make it a local value and not a resource does this exception go away. This exception only happens in Blend. It doesn't happen in Visual Studio (i'm using 2010), and it doesn't occur when I run the application.
I'm at the end of my rope here. This problem means I am completely unable to use Expression Blend.
Tried making it a dynamic resource?
I am not especially clear on the rules in play that determine Static vs Dynamic even give the answer below, but It has resolved a lot of issues for me when loading resources to change it from a Static to Dynamicresource.
What's the difference between StaticResource and DynamicResource in WPF?
Alright, after a little digging, I found this. The OP in this post has a situation quite similar to yours. His work around suggests merging resource dictionaries at the Usercontrol level rather than only through App.xaml.

Visual Studio crashes on opening XAML file

I try and open a XAML file in a silverlight project, VS crashes.
I can create a new Silverlight project, and open XAML files in that new project no problem. However even if I create a new XAML file in my existing project VS still crashes, so my hunch is that it's not the content of the XAML, but rather something else in the project.
Any suggestions on how to troubleshoot this further before I go down the laborious task of starting with an empty but working project, and adding the bits of the existing project until it crashes.
As it turns out my DesignTime ViewModel data was the source of the problem. I inject a design-time repository that populates various collections with suitable design-time data. After a bit of refactoring that was done around the same time as the Silverlight update was applied, I messed up one of the property setters. The validator throw the exception and these caused VS to crash.
In the end I debugged this by starting a second instance of Visual Studio attaching the debugger to the first instance, and setting a bunch of breakpoints in my view model locator and design-time repository.
I debated removing this question, but decided to leave it up, with this answer as I suspect I'm not the first person to have VS crash for no apparent reason.
Deleting the ngen cache worked for me. See What causes Visual Studio 2008 SP1 to crash when switch to Design View of a WPF application
Try deleting the .suo file. You will find it where your solution file is and it will have the same name as the solution file i.e.
MySolution.sln
MySolution.suo
I just had this problem and I solved it this way :
launch the project in debug mode, try then to look at you xaml.
It worked, after closing the program everything was alright.
It's quick and safe. (you don't delete any hidden files...)
Maybe it will work for you.

Resources