Please improve the message produced by CompositionException

Jul 21, 2009 at 1:37 PM
Edited Jul 21, 2009 at 1:39 PM

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

1) Object reference not set to an instance of an object. <--- WHERE?! Resulting in: An exception occurred while trying to create an instance of type 'Marmalade.Commerce.Web.Application.UserContext'. Resulting in: Cannot activate part 'Marmalade.Commerce.Web.Application.UserContext'. Element: Marmalade.Commerce.Web.Application.UserContext --> Marmalade.Commerce.Web.Application.UserContext --> AssemblyCatalog (Assembly="Marmalade.Commerce.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") Resulting in: Cannot get export 'Marmalade.Commerce.Web.Application.UserContext (ContractName="Marmalade.Commerce.Web.Application.UserContext")' from part 'Marmalade.Commerce.Web.Application.UserContext'. Element: Marmalade.Commerce.Web.Application.UserContext (ContractName="Marmalade.Commerce.Web.Application.UserContext") --> Marmalade.Commerce.Web.Application.UserContext --> AssemblyCatalog (Assembly="Marmalade.Commerce.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

If part of the programmer's code generates an exception like this, it would be helpful to know where the error actually comes from. Just a suggestion :P

Jul 21, 2009 at 6:27 PM

From the message, it’s occurring in the constructor. I would check the ctor, or any methods / members invoked in the ctor.

As far as the “Where”, what exactly are you looking for?

Regards

Glenn

From: NathanRidley [mailto:notifications@codeplex.com]
Sent: Tuesday, July 21, 2009 5:38 AM
To: Glenn Block
Subject: Please improve the message produced by CompositionException [MEF:63072]

From: NathanRidley

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) Object reference not set to an instance of an object. <--- WHERE?!
 
Resulting in: An exception occurred while trying to create an instance of type 'Marmalade.Commerce.Web.Application.UserContext'.
 
Resulting in: Cannot activate part 'Marmalade.Commerce.Web.Application.UserContext'.
Element: Marmalade.Commerce.Web.Application.UserContext --> Marmalade.Commerce.Web.Application.UserContext --> AssemblyCatalog (Assembly="Marmalade.Commerce.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
 
Resulting in: Cannot get export 'Marmalade.Commerce.Web.Application.UserContext (ContractName="Marmalade.Commerce.Web.Application.UserContext")' from part 'Marmalade.Commerce.Web.Application.UserContext'.
Element: Marmalade.Commerce.Web.Application.UserContext (ContractName="Marmalade.Commerce.Web.Application.UserContext") --> Marmalade.Commerce.Web.Application.UserContext --> AssemblyCatalog (Assembly="Marmalade.Commerce.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
If part of the programmer's code generates an exception like this, it would be helpful to know where the error actually comes from.
Just a suggestion :P

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jul 21, 2009 at 6:33 PM

I see what you mean about the constructor. A line number would be really handy though. I have since solved the problem, but stepping through to figure it out was a real pain. If an exception is being thrown and you guys are in fact trapping that exception, using the InnerException property would be a nice simple thing you could do seeing as currently you're leaving it set to null. Thanks for the reply.

Coordinator
Jul 21, 2009 at 7:01 PM

The CompositionException may wrap multiple errors, so there may be more than one "inner" exception.

You can get at the stack trace by looking at the Errors property of the CompositionException.  It is a list of CompositionErrors, and CompositionError has an Exception property which you can look at to find the stack trace to the original problem.

Aug 3, 2009 at 8:10 PM

Even with this information, the error is extremely unhelpful. If, as you say, the purpose of the Errors property is to break down the individual errors that occurred, then the errors that were created from exceptions in my code should display the exception that *my* code threw. Currently it does not do this; instead it shows an exception that originates in the MEF code AFTER my exception is thrown, leaving me with nothing but a useless "Object not set to an instance of an object" error. Now it's all well and good that I can identify from my code that the error is occurring inside a constructor; the issue occurs in complex code where there are multiple paths that could be followed inside the constructor and multiple stack levels beyond the constructor in which the error could occur.

Please, please, please keep a copy of my exception(s) somewhere to help me trace the origin of the error(s)! Currently it is a painful process of Step-Into in the Visual Studio debugger. I do find my errors when they occur, it just takes about a hundred times longer than it would need to if only the original exception that MY code threw had been preserved somewhere.

Thanks.

Coordinator
Aug 3, 2009 at 10:59 PM

We should be keeping a copy of the original exception that your code threw.  You say looking at the Exception property of the Error is an exception thrown by MEF after your exception is thrown.  I think if you look at the InnerException of the MEF exception, you will find your exception.  So to get the stack trace, put something like this in the debug watch window:

 

compositionException.Errors.First().Exception.InnerException.StackTrace

Thanks,

Daniel

 

 

Aug 3, 2009 at 11:09 PM
Nope, InnerException is null.

On Mon, Aug 3, 2009 at 10:59 PM, dsplaisted <notifications@codeplex.com> wrote:

From: dsplaisted

We should be keeping a copy of the original exception that your code threw.  You say looking at the Exception property of the Error is an exception thrown by MEF after your exception is thrown.  I think if you look at the InnerException of the MEF exception, you will find your exception.  So to get the stack trace, put something like this in the debug watch window:

 

compositionException.Errors.First().Exception.InnerException.StackTrace

Thanks,

Daniel

 

 

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Aug 4, 2009 at 1:07 AM

Can you post some code that will reproduce this problem?

Thanks,
Daniel