Upgrading your Visual Studio projects after installing new version of DevExpress

Here is the case:

  • You have already installed DevExpress
  • You have projects which are using DevExpress components on Visual Studio
  • You would like to install new version of DevExpress and using new components at your current projects

visual-studio-devexpress

Here is the remedy:

  • Do not remove previous version of DevExpress!!
  • Install new version. So two versions will be installed at the same time.
  • Upgrade your projects by using ProjectConverter (Start -> All Programs -> Developer Express v2012 vol 2 -> Components -> Tools -> ProjectConverter)
  • Remove previous version

You’re all set!

More information:
http://documentation.devexpress.com/#GeneralInformation/CustomDocument2221

Solved: “DisconnectedContext was detected” error when releasing Excel object in C#

You may face “DisconnectedContext was detected” error if you work with Excel interop objects in C#. This error causes crashing your application. It is really annoying issue and there is no specific resolution for this. So, I’ll give the general idea in this post.

Context 0xdf76a0′ is disconnected. Releasing the interfaces from the current context (context 0xdf7450). This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the application is completely done with the RuntimeCallableWrappers that represent COM components that live inside them.

DisconnectedContext error
DisconnectedContext error

Your code may look like this:

DisconnectedContext error
DisconnectedContext error

Your code may look like this:

Excel._Application app = new Excel.Application();
Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
Excel._Worksheet worksheet = null;
app.Visible = true;

worksheet.Cells[1, 1] = "test string";

workbook.SaveAs("C:\testfile.xlsx");

object misValue = System.Reflection.Missing.Value;
workbook.Close(true, misValue, misValue);
app.Quit();

releaseObject(worksheet);
releaseObject(workbook);
releaseObject(app);

At the first time the debugger goes into releaseObject, it gives DisconnectedContext error at first GC.WaitForPendingFinalizers() line in my case.

Solution

This issue has a quite complicated background. In order to simplify it, I wrote a post that is related to this problem a few days ago. Check this out:

http://port135.com/2012/08/08/how-to-properly-clean-up-excel-interop-objects-in-c/

If it doesn’t help:

  1. Make sure you release all objects accurately. Study Runtime Callable Wrapper and ReleaseComObject.
  2. Try to run your application in “release mode” instead of “debug mode“. Sometime this error doesn’t show up in “release mode”. So, you may want not to do anything about it.
  3. If the problem is still going on, publish your application (Project > Properties > Publish). Do you have the same problem? If you don’t, it doesn’t mean you have resolved it. You have just ignored it. If you want to resolve it forever, go back to step 1 and try hard.

How to remove an unused image from your resources in Visual Studio

In order to remove an unused image that stays in your resources:

  • Go to Project > Properties > Resources
  • Select whichever you want to remove and click on Remove Resource
Remove resource

After that, if you may get the error as shown below. Close Visual Studio and open it again in this case.

Code generation for property ‘ContentControl’ failed.  Error was: ‘Could not find file ‘C:\Users\nedim\Documents\Visual Studio 2010\Projects\projectname\projectname\Resources\1344394787_check.png’.’

Missing resource