locked
AssemblyCleanup throwing Exception in ASP.NET Core Project Targeting .NET 4.5.1 RRS feed

  • Question

  • I have an extremely simple ASP.NET Core Test Project and Test Class

    I am on Visual Studio 2015 Update 3

    project.json

    {
        "version": "1.0.0-*",
    
        "testRunner": "mstest",
    
        "dependencies": {
            "dotnet-test-mstest": "1.0.1-preview",
            "MSTest.TestFramework": "1.0.0-preview"
        },
    
        "frameworks": {
            "net451" : {}
        }
    }


    Class1.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace ClassLibrary1
    {
        [TestClass]
        public class Class1
        {
            [AssemblyInitialize]
            public static void Init(TestContext testContext)
            {
            }
    
            [TestMethod]
            public void Test()
            {
            }
    
            [AssemblyCleanup]
            public static void Clean()
            {
            }
        }
    }
    

    Whenever this is run, there is an exception thrown after AssemblyCleanup runs.

    Unhandled Exception: System.Runtime.Serialization.SerializationException: Type 'Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.RunCleanupResult' in assembly 'Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
       at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.UnitTestRunner.RunCleanup()
       at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTestsWithTestRunner(IEnumerable`1 tests, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, String source, UnitTestRunner testRunner)
       at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTestsInSource(IEnumerable`1 tests, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, String source, Boolean isDeploymentDone)
       at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle, Boolean isDeploymentDone)
       at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.RunTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle, TestRunCancellationToken runCancellationToken)
       at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
       at MSTest.Runner.DotNet.Program.Run(String[] args)
       at MSTest.Runner.DotNet.Program.Main(String[] args)

    Same issue happens when running with "dotnet test". These issues do not appear if my project.json is a netCoreApp, but I need to be able to target net451:

    {
        "version": "1.0.0-*",
    
        "testRunner": "mstest",
    
        "dependencies": {
            "dotnet-test-mstest": "1.0.1-preview",
            "MSTest.TestFramework": "1.0.0-preview"
        },
    
        "frameworks": {
            "netcoreapp1.0": {
                "imports": [
                    "dnxcore50",
                    "portable-net45+win8"
                ],
    
                "dependencies": {
                    "Microsoft.NETCore.App": {
                        "version": "1.0.0",
                        "type": "platform"
                    }
                }
            }
        }
    }

    Wednesday, July 13, 2016 3:52 PM

Answers

  • Hi Adam Holden,

    Thanks for your response.

    I tested the project  you offered. And I got the same error message in the Output:

    But it works well when use this  project.json file:

    {
      "version": "1.0.0-*",
    
      "testRunner": "mstest",
    
      "dependencies": {
        "dotnet-test-mstest": "1.0.1-preview",
        "MSTest.TestFramework": "1.0.0-preview"
      },
    
      "frameworks": {
        "netcoreapp1.0": {
          "imports": [
            "dnxcore50",
            "portable-net45+win8"
          ],
      
          "dependencies": {
            "Microsoft.NETCore.App": {
              "version": "1.0.0-rc2-3002702",
              "type": "platform"
            }
          }
        }
      }
    }

    So from our test results. I think this is an issue when target net451. I have logged this issue to the Microsoft Connect team:

    https://connect.microsoft.com/VisualStudio/feedback/details/2956805

    You can vote it and add your comments.

    Best Regards,

    Lake  Xiao

    • Proposed as answer by lake Xiao Thursday, July 21, 2016 2:07 AM
    • Marked as answer by lake Xiao Friday, July 29, 2016 6:55 AM
    Thursday, July 21, 2016 2:07 AM

All replies

  • Hi Adam Holden,

    I follow the steps in this blog to do unit test for ASP .NET Core application.

    But after I replace the content of the project.json file with the following:

    {
      "version": "1.0.0-*",
    
      "testRunner": "mstest",
    
      "dependencies": {
        "dotnet-test-mstest": "1.0.1-preview",
        "MSTest.TestFramework": "1.0.0-preview"
      },
    
      "frameworks": {
        "netcoreapp1.0": {
          "imports": [
            "dnxcore50",
            "portable-net45+win8"
          ],
      
          "dependencies": {
            "Microsoft.NETCore.App": {
              "version": "1.0.0-rc2-3002702",
              "type": "platform"
            }
          }
        }
      }
    }

    When I add the using Microsoft.VisualStudio.TestTools.UnitTesting to my .cs file. I got this warning message:

    Do you know how to resolve this?  I have tried this in three machine and got the same results.

    Since the ASP.NET Core was released recently. And for your issue "fail target net451". I suggest you could also try to add your comment in that blog, some other members may help you to solve this problem.

    Best Regards,

    Lake Xiao


    • Edited by lake Xiao Thursday, July 14, 2016 6:47 AM
    Thursday, July 14, 2016 6:46 AM
  • Try removing the "-rc2-3002702"and it might work.
    Thursday, July 14, 2016 2:04 PM
  • Hi Adam Holden,

    I found the cause of my problem, after I install the update of Visual Studio. I can do the unit test for ASP.NET Core application successfully.

    And for your issue, I use the project.json file you provided, and it works well for me and I don't encounter your problem:

    So I think the problem is in your Visual Studio. Please try to install the VS2015 Update3 KB3165756 in Tools->Extension and Updates. If still no help, I suggest you could repair your Visual Studio then try it again.

    Best Regards,

    Lake Xiao

    • Marked as answer by Adam Holden Monday, July 18, 2016 2:44 PM
    • Unmarked as answer by Adam Holden Tuesday, July 19, 2016 9:32 PM
    Monday, July 18, 2016 6:54 AM
  • Hi Adam Holden,

    Have you tried installed the VS2015 Update3 KB3165756? Do you still get the same error message?

    If have any update about your issue, please feel free to let me know.

    Best Regards,

    Lake Xiao

    Wednesday, July 20, 2016 1:11 AM
  • Yes, I installed the update, but I believe I got ahead of myself when saying this was fixed. I meant to elaborate after unmarking answered yesterday. 

    I have prepared an example solution that will hopefully illustrate the issue I am encountering, I am still getting an error after Assembly Cleanup. Please try this test project below, if you run the test, it may show up as passing in the Test Explorer, but the output will have a stack trace, and running it via "dotnet test" will show the error more clearly.

    Example Solution



    • Edited by Adam Holden Wednesday, July 20, 2016 2:51 PM
    Wednesday, July 20, 2016 2:40 PM
  • Hi Adam Holden,

    Thanks for your response.

    I tested the project  you offered. And I got the same error message in the Output:

    But it works well when use this  project.json file:

    {
      "version": "1.0.0-*",
    
      "testRunner": "mstest",
    
      "dependencies": {
        "dotnet-test-mstest": "1.0.1-preview",
        "MSTest.TestFramework": "1.0.0-preview"
      },
    
      "frameworks": {
        "netcoreapp1.0": {
          "imports": [
            "dnxcore50",
            "portable-net45+win8"
          ],
      
          "dependencies": {
            "Microsoft.NETCore.App": {
              "version": "1.0.0-rc2-3002702",
              "type": "platform"
            }
          }
        }
      }
    }

    So from our test results. I think this is an issue when target net451. I have logged this issue to the Microsoft Connect team:

    https://connect.microsoft.com/VisualStudio/feedback/details/2956805

    You can vote it and add your comments.

    Best Regards,

    Lake  Xiao

    • Proposed as answer by lake Xiao Thursday, July 21, 2016 2:07 AM
    • Marked as answer by lake Xiao Friday, July 29, 2016 6:55 AM
    Thursday, July 21, 2016 2:07 AM