Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.TypeLoadException exception while running unit test cases #36

Open
YadavRohan opened this issue Oct 4, 2017 · 1 comment
Open

Comments

@YadavRohan
Copy link

Hi,
I tried to run Unit test cases from test explorer, but I am getting System.TypeLoadException.
Below is the error message -

Test Name: TestAddStock
Test FullName: Inventory.UnitTests.InventoryServiceTests.TestAddStock
Test Source: D:\service-fabric-dotnet-web-reference-app\ReferenceApp\Inventory.UnitTests\InventoryServiceTests.cs : line 67
Test Outcome: Failed
Test Duration: 0:00:00

Result StackTrace:
at Inventory.UnitTests.InventoryServiceTests..cctor()
--- End of inner exception stack trace ---
at Inventory.UnitTests.InventoryServiceTests..ctor()
Result Message: Unable to create instance of class Inventory.UnitTests.InventoryServiceTests. Error: System.TypeInitializationException: The type initializer for 'Inventory.UnitTests.InventoryServiceTests' threw an exception. ---> System.TypeLoadException: Method 'ReportApplicationHealth' in type 'Mocks.MockCodePackageActivationContext' from assembly 'Mocks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation..

Steps to reproduce the issue.

  1. Clone the repo
  2. Changed Test -> Test Settings -> Default Processor Architecture to X64.
  3. Rebuild the solution
  4. Run the test.

I am getting same exception for all the other test cases.

Am I missing something. Can anybody please look into this.

Thank you!

@benleduc
Copy link

Hi,

I was having an issue similar yours.

I eventually managed to understand the root cause and fixed the issue.

The mocks from https://github.com/loekd/ServiceFabric.Mocks/ implement interfaces from the System.Fabric assembly.

The System.Fabric assemblies are also installed in the GAC when installing the fabric or the sdk.

I had installed fabric version 6 on my machine (latest) but then had to uninstall it and install 5.6 as it’s what my team is using.

The problem is that when I removed version 6, the installer didn’t remove the System.Fabric (and other related version 6 fabric assemblies) from the GAC and the .Net framework was confused between what was defined in the manifest of the tests (referencing version 5.6) and what it was loading (it’s talking the latest version from the GAC which is version 6).

The fix was to remove System.Fabric version 6 and related version 6 fabric assemblies from the GAC using gacutil.

The installer from version 5.6 do remove everything from the GAC, the issue only reproes with the fabric version 6 installer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants