2

I’ve inherited an ASP.Net web application comprising of VB.Net projects. I’ve added a C# project to the solution, which references several of the VB.Net projects.

The application uses Castle Windsor as a DI container and dependencies are registered in one of the VB.Net projects.

In that VB.Net project. to avoid circular references, I use the “FromAssemblyNamed”, method to register the dependencies that are defined in my C# project:

container.Register(Classes.FromAssemblyNamed("x.y.z.TLBusinessLayerV2").BasedOn(Of IService).WithService.FromInterface().Configure(Function(c) c.LifeStyle.Transient))

This is working fine when I run the application.

However, there is an existing Unit Test project. In that I have added a reference to my C# assembly. When I run all of the tests, some of the tests fail when they hit the code above with the following exception:

System.IO.FileNotFoundException: Could not load file or assembly x.y.z.TLBusinessLayerV2' or one of its dependencies. The system cannot find the file specified.

  • All of the assemblies referenced by the C# Assembly are also referenced by the Unit Test project.
  • The Target CPU for the VB.Net project, C# project and Unit Test project are all set to x86.

If I then run one of the failed tests individually, the test passes.

Q. Why are the Tests failing when I run them all? Any help much appreciated.

1 Answer 1

1

The solution to this issue is to add a dummy class to the Unit Test project, that references a class in the assembly (loaded in "Classes.FromAssemblyNamed"). Something like:

Public Class DummyDependencies
        Private Xyz As Object = GetType(<name of a class in target assembly>)
End Class

This appears to enforce the reference to the assembly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.