Using Moq during Blend Development

This may be a bit, but suppose I want to use Moq in the ViewModel to create some design-time data, for example:

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

The layout can be customized to do something, but you get the point.

My problem is that during development in Blend, this code throws an InvalidCastException, with a message in the lines “Cannot strip an object of type Castle.Proxies.ISomeDependencyProxy2b3a8f318828ffffbb1212bdf3d50d3fc” for input “ISomeDependency.” Although this does not necessarily apply to MoomeDependency. castle, I hope the Moq example helps;)

Any idea why this is?

Thank!

+5
3

, , (Blend_RuntimeGeneratedTypesAssembly), .

.

CRAZY.

+1

, , , , Blend 4 datacontexts .

, , VM, ..

, .

, - , , , - . . , , .

+1

: github: https://github.com/GeniusCode/GeniusCode.Components.DynamicDuck

, . duck/mock msil, .

I wrote about this here: http://blogs.geniuscode.net/JeremiahRedekop/?p=255

We are working on the release of the library under MS-PL and are deploying on GitHub.

+1
source

All Articles