I have a legacy application written in Web Forms and VB .NET. I'm fed up to the back teeth with this combination, so I am trying to write new functionality in Web API controllers instead of ashx handlers. Good for me. I also prefer C# so I am trying to load my controller actions from a C# library instead of writing them in VB .NET.
I have tried to do the following:
- Use MapRoute to name an assembly to load from (can't do this, can only see MapHttpRoute, MapRoute is not available. MapHttpRoute has no assembly option)
- Write my own assembly resolver to load my other project DLL at runtime. This doesn't work either, VB NET complains about how the code I am using doesn't implement GetAssemblies correctly.
This is the code I am trying to use:
Public Class CustomAssemblyResolver
Inherits IAssembliesResolver
Public Function IAssembliesResolver_GetAssemblies() As ICollection(Of Assembly) Implements IAssembliesResolver.GetAssemblies
Dim baseAssemblies As List(Of Assembly) = AppDomain.CurrentDomain.GetAssemblies().ToList()
Dim controllersAssembly = Assembly.LoadFrom("APIControllers.dll")
baseAssemblies.Add(controllersAssembly)
Return baseAssemblies
'Throw New NotImplementedException
End Function
End Class
The error I get is "Interface IAssembliesResolver is not implemented by this class".
What is the easiest way to load my API controllers from a seperate project? The main project is in VB .NET, the project I am loading is in C#.
EDIT: The issue is complicated by the layout at the moment. For simplicity, oldyuck is the web forms/vb .net thing, and newfast is the new C# project.
oldyuck is the main legacy project. It has a huge monolithic class that does everything. This is instantiated as a huge object that does everything. It's also a Web Forms/VB .NET travesty. newfast is my C# API Controller project. It needs the huge monolithic object from oldyuck to do anything on the database etc.
newfast can depend on oldyuck, and then I can depend on the huge object, and instantiate it etc, but it won't wind up in the /bin/ folder when oldyuck builds.
oldyuck can depend on newfast, and then it will end up in the /bin/ folder. But in this setup, newfast can't depend on the god object from oldyuck, so it can't use any of that code, and there doesn't seem to be a way to pass that object along to it.
I'm stuck. Help :(