microsoft / UnitTestBoilerplateGenerator

An extension for Visual Studio that generates a unit test boilerplate from a given class, setting up mocks for all dependencies. Supports NUnit, Visual Studio Test, Moq and SimpleStubs.
MIT License
158 stars 51 forks source link

Exception when clicking on "Create Unit test boilerpalte..." #24

Closed binpick closed 6 years ago

binpick commented 6 years ago

Installed product versions

Description

This extension was working for a time. Now, every time i try to create a new xx i get the exception:

"The type initializer for UnitTestBoilerplate.StaticBoilerplateSettings threw an exception."

Steps to recreate

  1. Right click on any class
  2. Select "Create Unit test boilerpalte..."

Current behavior

No unit test file is created due to the exception.

Expected behavior

A new unit test file should be created.

binpick commented 6 years ago

I noticed that i am not able to save the boilerplate template settings. After e.g. resetting to default, i see the default template. After selecting ok and opening the settings again, all fields are empty.

RandomEngy commented 6 years ago

Do you get any more details for the exception, like the stack trace? Or does it only say that it threw an exception and not tell you anything else?

binpick commented 6 years ago

No, there is no stacktrace, just this exception message. Don't know if there is a log file somewhere?

RandomEngy commented 6 years ago

Can you uninstall the extension and try this one? I added more logging that should tell me what's going on: http://engy.us/misc/UnitTestBoilerplate.vsix

binpick commented 6 years ago

Thank you. I installed it and get the same exception. Where do i find the log file?

binpick commented 6 years ago

Btw, i have this issue on different computers.

binpick commented 6 years ago

...forgot to mention, great extension. I am using it in all of my projects, hope we can fix it :-)

binpick commented 6 years ago

UTBG Self Test -> Run: "Sequence contains no matching element"

binpick commented 6 years ago

If i reset UTGB settings to default, Visual Studio hangs and then it crashes (after pressing OK).

binpick commented 6 years ago

This is from the windows event view:

Application: devenv.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException at UnitTestBoilerplate.StaticBoilerplateSettings..cctor()

Exception Info: System.TypeInitializationException at UnitTestBoilerplate.ViewModel.FileContentsOptionsDialogViewModel.Apply() at UnitTestBoilerplate.View.FileContentsOptionsDialogPage.OnApply(PageApplyEventArgs) at Microsoft.VisualStudio.Shell.DialogPage+DialogSubclass.WndProc(System.Windows.Forms.Message ByRef) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr, Int32, IntPtr, IntPtr)

binpick commented 6 years ago

So seems that i cannot save/load the settings. That's why the fields are empty when opening the settings. After resetting to default, VS crashes. Where are the settings stored?

In VS 2017 Community the extension works.

RandomEngy commented 6 years ago

If you open VS, then right click on a file and select "Create Unit Test Boilerplate..." it should open a dialog box with more details this time. But that stack trace in the event log should give me somewhere to start, thanks.

binpick commented 6 years ago

After right click i just get the expcetion window:

image

I compared the settings of VS2017 and VS2015 in the registry and i noticed that the key where the settings are stored is missing for VS 2015. This explains why i am getting empty fields when opening the settings in VS 2015, but i don't know the reason.

VS 2017 (missing in VS 2015): image

So seems that i cannot write the settings into the registry. Probably it is not a UTGB bug but a VS bug, but i dont' know the reason. I have it on different PCs.

RandomEngy commented 6 years ago

Hmm, I installed VS 2015 community and everything is working fine over here. I'm rather surprised you're seeing the issue on multiple computers. What OS are you running?

One thing to remember about the registry is the \VisualStudio\14.0 is for VS 2015. In VS 2017 (which is version 15, I know, confusing), whisks the registry settings off to some private place:

\REGISTRY\A{f3b03746-a87a-c8bf-6859-2869b2937396}\Software\Microsoft\VisualStudio\15.0_a703f143\UnitTestBoilerplateGenerator\Template_VisualStudio_Moq_File

I'm also a bit surprised that with that .vsix you're still getting the old error dialog, as I put a giant try/catch around the StaticBoilerplateSettings static ctor. Are you sure you uninstalled the previous version?

binpick commented 6 years ago

Hi, i am running Win10. I am going to deinstall the current version again, clean up the extension folder and reinstall it.

binpick commented 6 years ago

I reinstalled and get the same error. Only the message box with the exception message. I do have the new version installed since i have the Self test menu, which i had not before. When trying to reset the settings VS crashes.

RandomEngy commented 6 years ago

Curses! It sounds like something is causing SettingsManager.GetWritableSettingsStore to throw a FileNotFoundException, but I can't reproduce it. I'm running Win10 as well.

I'll try it on a clean Win10 VM.

RandomEngy commented 6 years ago

Okay reproduced the error. Apparently Visual Studio stopped including Newtonsoft.Json in the VSIX output for some reason. Now I need to figure out why and how to include it again.

RandomEngy commented 6 years ago

Should be fixed in 1.7.1.

binpick commented 6 years ago

Awesome. Thank you for the support, works like a charme.

RandomEngy commented 6 years ago

Leave a review on the gallery page if you like the extension!

binpick commented 6 years ago

You'r right, i did it.