Why has Visual Studio's Windows Forms Designer stopped working? - visual-studio

I'm in the process of cleaning up an old bit of C++-CLI software by decoupling business logic from the GUI. Despite the fact that I've left the windows forms designer code well alone, it now won't display my form and instead, throws an exception:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
The call stack looks like this:
at EnvDTE.CodeFunction.GetStartPoint(vsCMPart Part)
at Microsoft.VisualC.CppCodeParser.OnMethodPopulateStatements(Object sender, EventArgs e)
at System.CodeDom.CodeMemberMethod.get_Statements()
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
...none of which is my code. What might I have disturbed?

Based on the call stack it looks like the WinForms designer is choking trying to read the code inside the InitializeComponents method in the generated file. The actual faulting party is the C++ code model implementation.
What's most likely happening here is a particular statement in the method is causing the code model to error here. I would start by commenting out the entire method, verifying that fixes the problem and then slowly uncommenting sections until I tracked down the offending line

Check if there is none of your own code in InitializeComponent() function.I replaced it and it works normally now)

i googled the error and there were a few threads citing various different applications that all produce this error:
http://forums.iis.net/t/1148764.aspx/1
and
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/11e91d76-f5f3-45c3-b3f6-30c1e4121b9f/
being just two
the chief cause of this error seems to be a user or process attempting to access, run or write to something it does not have access to.
Have you tried running the application as an administrator?
if that doesn't work make sure both the project folder and the application folder are on the same partition as that can affect permissions.
you have not upgraded your OS since that application was installed by any chance? If so your GUID may not match the stored GUID on the Application and that could be causing the error uninstalling/re-installing will fix this.
hope that helps

Related

How to find out in unmanaged code if it is running in managed context

I am writing an Excel VSTO add-in. This add-in loads and runs unmanaged code.
In the startup code of the unmanaged dll, an invisible window for request handling is created. This function call causes a managed exception (LoaderLock) and if I remove it, everything works. I want to avoid creating an extra version just because of this. Is there a way for the unmanaged code to find out at runtime whether it is running in a managed thread? In this case, I could add a runtime check. The window is only needed in a fully unmanaged environment.
Note 1: The issue only occurs in this Excel add-in; a stand-alone managed console application using the unmanaged dll does not show this problem.
Note 2: I know that there are many things that should not be done from within DllMain. What I am doing has been working for more than a decade in managed and unmanaged environments and I want to keep code changes as small as possible.
Checking if mscoree.dll has been loaded has done the trick for me:
if (::GetModuleHandleW(L"mscoree.dll") == nullptr)
This: Checking if a WIN32 / Unmanaged DLL is loaded from a COM module on runtime and this: What does it mean when code "runs on" the .NET CLR? helped.
As exposed in the comments below, this does not tell which type of thread has loaded the dll, but only whether there is any managed component in the process. A more precise check would still be preferred. For the moment, I can live with this solution.

Resource-related error condition in Windows Forms C++ application

I am working on a legacy Windows Forms application using VS 2008 under C++ and face a weird problem. The form uses an ImageList object, to which two bitmap images have been added. At run-time, I get the following error in Debug mode (in the Release mode, the application just doens't launch):
An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the specified culture or the neutral culture.
Make sure "MyApp.Form1.resources" was correctly embedded or linked into assembly "MyApp" at compile time,
or that all the satellite assemblies required are loadable and fully signed.
The crash occurs at the first line of this block:
this->imageList1->ImageStream = (__try_cast<System::Windows::Forms::ImageListStreamer* >(resources->GetObject(S"imageList1.ImageStream")));
this->imageList1->TransparentColor = System::Drawing::Color::Transparent;
this->imageList1->Images->SetKeyName(0, S"Nok32.png");
this->imageList1->Images->SetKeyName(1, S"Ok32.png");
This is pretty puzzling, because I copied the application from an existing one which works fine. I just changed the namespaces. And if I remove the two images from the list, the application works.
I found several posts on forums about this or similar problems, but none could really help me. I don't think that Visual Studio can be blamed. I tried with frameworks 2.0 and 3.0, to no avail. Fully comparing the sources of both applications, I can't see a significant difference.
Any hint ?
Solved: there was an old namespace left in the project file (.vcproj) !

OpenPop.net called from unmanaged code (causing GPF)

I would like to create a C# managed x86 DLL wrapper for OpenPop that I call from my unmanaged (C) code.
I have done this for other products in the past using the NuGet "UnmanagedExports" package which seems to work well.
I tried doing this with the OpenPop.net package but I get a GPF as soon as I call "client = new Pop3Client();". If I remove all calls to OpenPop, the DLL loads and returns properly.
Furthermore, I am accessing OpenPop from within a try/catch structure yet it still fails with a GPF (instead of catching this error).
I installed the latest OpenPop.net package v2.0.6.1120 and I am targeting .net v4.5.2 (I also tried v4.0 with no difference).
Can OpenPop.net be used like this in conjunction with the UnmanagedExports package? If so, any suggestions on how I might debug this?
Thank you!
(I realize that this is free software so support is no expected so I am more than happy to pay for support if required)
I found the problem... I was not copying the OpenPop.dll to my application folder where my DLL is loaded. Once the file was available, the GPF no longer occurred. Too bad this was not able to be trapped by the C# exception handler.

Visual Studio 2010 keeps complaining about Invalid XML although there is none (WP7)

I experience a strange behaviour in Visual Studio 2010 when creating Windows Phone 7 apps. After some time VS starts to complain about Invalid XAML although there is no problem and the app compiles and runs just fine.
It bugges me because I cannot use the visual desingner saying "Exception was thrown on "DataTemplate": Invalid XML" and there is a DataTemplate higlighted in the code. The data template is always ok, VS does not complain about it when copy-pasted to another project.
I found out that problematic are usually the DataTemplates with custom converters or when usin g classes like PhonePerformance.
Sometimes the error is "Exception thrown was due to document error: Invalid XML" and nothing is even highlighted in the XAML file.
I tried reinstalling .NET. Visual Studio etc. and the problem occurs on two separated machines so I do not think it is specific to my configuration. It may be specific to my code.
Anyone experienced similar behaviour?
When using XAML, if you reference a library that needs to be evaluated but can't be at design time you get this kind of error. You can turn off the visual editor and just work in XAML - that will stop the error (and save you time).
You reinstalled .NET and VisualStudio??? You should have just spun up a second instance, opened the solution in both, then attached the debugger from one to the second and opened up the visual editor. It would have told you exactly what in your code was causing the problem. Also DesignerProperties.IsInDesignMode in your converters. Jeez. You wasted so much time :(
As for design time data, that's tricky. Either you have DesignTimeDataWithDesignTimeCreatableTypes that aren't or DesignData that can't create proxies for your real types (for whatever reason, had this issue many times deep in the past).
The only way to figure this out is to debug one instance from another. Its actually not that hard. I do it alot (debugging WF4 ActivityDesigners).
A friend has found a solution and you would not believe where the problem is. This happens if you have a space in the name of your assembly. I found out that I really have a space in assembly name in all the problematic projects, renamed the assemblies and the designer works again.
The solution is also mentioned here http://forums.silverlight.net/t/115011.aspx/1

"An unhandled non-continuable exception was thrown during process load"

This error message appears on a colleague's machine when he tries to launch a Windows application he's working on:
An unhandled non-continuable exception was thrown during process load
What does this mean, and how does one go about investigating what is causing it?
I have Googled it, but haven't found a clear answer. It seems to have something to do with problems loading DLLs.
Right I'm looking over this issue in my own code at the moment - for anyone who is having this issue, here's some pointers:
There is a fairly involved thread discussing it here: http://bytes.com/topic/net/answers/555706-unhandled-non-continuable-exception-thrown-during-process-load
Are you linking to Winmm.lib? It's got problems, can you avoid using it?
Are you using C++/CLI? If so, consider delay loading the C++/CLI module.
Any other hints, please post - this crops up from time to time and can be problematic!
More details are on: http://www.dwmkerr.com/post/2012/02/08/Debugger-An-unhandled-non-continuable-exception-was-thrown-during-process-load.aspx
Is there more information in the error message, maybe in the debug console? If there's a stack trace available, it might point you to the problem application, or better yet, the DLL that's causing the problem. The next step would be to see if there's an update available for that DLL.
I found that enabling the "Read&Execute" permission on a dll that was checked in to version control solved this problem.
The first thing I tried was to copy my whole Debug/ directory somewhere and the app ran fine there, then I checked the properties of each of the original dlls and enabled execute.
I had the same issue and it turned out that a DLL compiled for x64 in a x86 project was the culprit. Replacing the DLL with the x86 version resolved the issue.

Resources