Cannot get Last Exception
See original GitHub issueDescription
I am working on a unit test project. I have a base test file where I have the following line in my Assembly Initialize method.
AppDomain.CurrentDomain.FirstChanceException += (s, e) => LastException = e.Exception;
This line will store the last thrown exception in the Last Exception field. This can then be called by the following line and inserted into reports.
WebUtility.HtmlEncode(LastException.Message)
This worked in the old Test Framework NuGet package:
VS.QualityTools.UnitTestFramework (version 15.0.27323.2)
but in the new Test Framework NuGet package:
MSTest.TestFramework (version 1.4.0)
I see the following error passed to the Last Exception field.
Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources, Version=14.0.0.0, Culture=en-GB, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Steps to reproduce
- Put the following line in a test class:
public static Exception LastException { get; private set; }
- Put the following line in a test method:
AppDomain.CurrentDomain.FirstChanceException += (s, e) => LastException = e.Exception;
- Follow that line with this line:
throw new System.Exception("Test Error Message");
- Run the unit test in debug mode
- When the exception is thrown, press F10 to step to the next line
- When execution moves to LastException = e.Exception, hover over e.Exception
Expected behavior
Last Exception should equal System.Exception with a message of “Test Error Message”.
Actual behavior
An error is displayed:
Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources, Version=14.0.0.0, Culture=en-GB, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Environment
Windows 10 .Net Framework 4.7.2 MSTest.TestFramework (version 1.4.0) MSTest.TestAdapter (version 1.4.0)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:14 (8 by maintainers)
Top GitHub Comments
Found a workaround for this issue the culture needs to be set on culture
en
instead ofen-US
.Tried
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
and it seems to be working. By the same logicCultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en");
should work as well.@karanjitsingh I have added the following as the first line of the Test Method. I get the same error.
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
If you add the following, can you reproduce my issue?
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-GB");