views:

83

answers:

1

This might be a bit out there, but suppose I want to use Moq in a ViewModel to create some design time data, like so:

public class SomeViewModel
{
   public SomeViewModel(ISomeDependency dependency)
   {
      if (IsInDesignMode)
      {
         var mock = new Mock<ISomeDependency>();
         dependency = mock.Object; // this throws!  
      }
   }
}

The mock could be set up to do some stuff, but you get the idea.

My problem is that at design-time in Blend, this code throws an InvalidCastException, with the message along the lines of "Unable to cast object of type 'Castle.Proxies.ISomeDependencyProxy2b3a8f3188284ff0b1129bdf3d50d3fc' to type 'ISomeDependency'." While this doesn't necessarily look to be Moq related but Castle related, I hope the Moq example helps ;)

Any idea why that is?

Thanks!

A: 

I'm having a similar issue, except that the cast is coming from a dynamically generated assembly (Blend_RuntimeGeneratedTypesAssembly) type that is masquerading as one of my types.

For no apparent reason.

Which is driving me CRAZY.

Will
Caused by type assembly A targeting the full framework and design time data project B targeting the client factory. Caused all kinds of weird shit to happen.
Will