locked
unable to create a silverlight unit test project on vs2012

    Question

  • Hi all,

    I want to use the Silverlight toolkit to create a Silverlight unit test project in VS2012. To this purpose, I installed the latest Silverlight Toolkit (dec11) on a machine that has both VS2010 and VS2012. Both VS versions are installed in their default paths, and this is a x64 machine.

    Initially, the "Silverlight Unit Test Application" template simply wouldn't show up in VS2012. After a few attempts at uninstalling and reinstalling the toolkit, I stumbled on this page: http://stackoverflow.com/questions/3170971/silverlight-4-unit-testing which explains what happens when your VS is not installed in the default path. Although this is not my case, it made me suspect that the toolkit installer was only installing the template for VS2010, and not for VS2012, so I looked into the template folder for VS2010, and sure enough I found templates for Silverlight Unit Test Application in ItemTemplates and ProjectTemplates. I copied those to the proper VS2012 folders, ran devenv /installvstemplates, and now I can see the project template in my New Project window in VS2012.

    Unfortunately, if I attempt to create any such project, I immediately get a message box saying "object reference not set to an instance of an object" and nothing else. At this point, I'm stuck and I need help.

    Friday, September 21, 2012 9:28 AM

Answers

All replies

  • Monday, September 24, 2012 2:51 AM
  • I got to the same stage as Zappo1980 but installing the SL UT adapter has no effect. Still the 'object reference' error message.

    Any further ideas?

    Thanks.

    Tuesday, November 6, 2012 8:12 PM
  • I've found that I can fix that by running gacutil -i on the DLLs in C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Testing. But it's still not working. When I run a test, it never completes (I have to restart VS to stop the test).
    Wednesday, November 7, 2012 11:35 AM
  • I'm having the same object reference problem when creating a new Silverlight Unit Test Project, but your gacutil fix didn't change anything for me. Are you sure that's all you did to fix the problem?


    Raymond Saltrelli | Software Engineer | Mapping Analytics

    Friday, January 18, 2013 3:36 PM
  • What you have to do is edit the ".vstemplate" file and under <WizardExtension> replace the <Assembly> line with the new one referencing vs2012:

    <Assembly>Microsoft.VisualStudio.Silverlight, Version=11.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>

    Tuesday, January 29, 2013 11:36 AM
  • I was struggling with this problem too and the thing which solved the problem for me was to copy the templates as described by Zappo1980. The VS2010 files were zip's whilst the VS2012 were not so, after copying the zips over, I extracted them in place. This left a zip plus a directory in the project and class TemplateDirectories - make sure you delete the zips to prevent 2 versions of the template being listed when creating a new project/item.

    To prevent the  'object reference not set to an instance of an object' problem edit the project .vstemplate file as described by adrian_hara and then run devenv /installvstemplates.

    I believe installing the testing dll'#s in the GAC was a red herring and although I did it I don't think it was needed. In fact I don't think it even installed them in the GAC as when I tried to uninstall them it failed and I couldn't navigate to them in the GAC explorer.

    Finally, I had problems when using Moq. I installed Moq using nuget but got the following exception when my code hit the <fake object>.object property:

    "The type initializer for 'Moq.Mock`1' threw an exception"

    The solution after some digging turned out to be that I had to install Castle Core manually.

    Harder work than it should be but all good now.

    Hope this help others.

    Cheers

    Neil

    Thursday, October 17, 2013 2:01 PM
  • I was struggling with this problem too and the thing which solved the problem for me was to copy the templates as described by Zappo1980. The VS2010 files were zip's whilst the VS2012 were not so, after copying the zips over, I extracted them in place. This left a zip plus a directory in the project and class TemplateDirectories - make sure you delete the zips to prevent 2 versions of the template being listed when creating a new project/item.

    To prevent the  'object reference not set to an instance of an object' problem edit the project .vstemplate file as described by adrian_hara and then run devenv /installvstemplates.

    I believe installing the testing dll'#s in the GAC was a red herring and although I did it I don't think it was needed. In fact I don't think it even installed them in the GAC as when I tried to uninstall them it failed and I couldn't navigate to them in the GAC explorer.

    Finally, I had problems when using Moq. I installed Moq using nuget but got the following exception when my code hit the <fake object>.object property:

    "The type initializer for 'Moq.Mock`1' threw an exception"

    The solution after some digging turned out to be that I had to install Castle Core manually.

    Harder work than it should be but all good now.

    Hope this help others.

    Cheers

    Neil

    I am following along with the "Core Silverlight 4" videos on Pluralsight and in the "Unit Tests" video he creates a Silverlight Unit Test Project. But since I am using Visual Studio 2012, this template doesn't show. This solution from Neil (which also referenced Zappo's manual file copy method) allowed me to get the template installed. Thanks!
    Tuesday, October 14, 2014 6:16 PM