0

I am working on an ASP.NET MVC app using oData 4. Up until yesterday they project was in VB.NET. We are now finally attempting to move from VB.NET to C#. I've tried to introduce 2 controllers written in C# into the project and in both instances, receive the dreaded "No type was found that matches the controller named ***" error when attempting to access either controller.

The first one was a new controller. It looks like this:

using System.Data.Entity.Infrastructure;
using System.Net;
using System.Web.Http;
using System.Web.OData;

namespace Controllers
{
    public class ORDER_LINE_SUMMARYController : ODataController
    {
        private Entities db = new Entities();
        [EnableQuery()]
        public IQueryable<ORDER_LINE_SUMMARY> GetORDER_LINE_SUMMARY()
        {
            return db.ORDER_LINE_SUMMARY;
        }
        [EnableQuery()]
        public SingleResult<ORDER_LINE_SUMMARY> GetORDER_LINE_SUMMARY([FromODataUri()] decimal key)
        {
            return SingleResult.Create(db.ORDER_LINE_SUMMARY.Where(ORDER_LINE_SUMMARY => ORDER_LINE_SUMMARY.ID == key));
        }
        protected override void Dispose(bool disposing)
        {
            if ((disposing))
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
        private bool ORDER_LINE_SUMMARYExists(decimal key)
        {
            return db.ORDER_LINE_SUMMARY.Count(e => e.ID == key) > 0;
        }
    }
}

In order to make certain that I didn't miss a step in incorporating this new controller, I also tried replacing an existing VB.NET controller with a C# controller and receive the same error. Except for the entity name, the code is essentially identical to the one above, so I'm not positing it here for brevity's sake.

One interesting note, and I think this is germane to the underlying problem. When I added the new C# controller to replace the existing VB.NET one I hadn't yet removed the VB.NET controller from the project. Obviously the class names for both are the same, however; the .NET compiler didn't error or otherwise complain about this. I suspect this issue may be related to attempting to mix C# and VB.NET within the same assembly due to this.

Any suggestions or ideas would be greatly appreciated. TIA.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Mike Feltman
  • 5,160
  • 1
  • 17
  • 38
  • Thanks for the edit. :) – Mike Feltman Nov 02 '16 at 13:37
  • 2
    Sorry, fixing routes sucks and nothing strikes me as obvious. Except that you should read the FRAMEWORK_DESIGN_GUIDELINES –  Nov 02 '16 at 13:37
  • FYI I just added the VB.NET controller described above back to the project and it works despite the existence of a C# class by the same name. – Mike Feltman Nov 02 '16 at 13:38
  • Have you tried just creating a new project based in C# and working from there? Or do you have the correct references set? – Kixoka Nov 02 '16 at 13:38
  • Thank Will. I'm pretty certain it's got nothing to do with routes. It seems to be related to mixing C# and VB.NET. – Mike Feltman Nov 02 '16 at 13:39
  • 1
    @Kixoka, I have created a C# project that accesses these 2 entities and it works. The controller code is the same in both projects. Migrating the entire project to C# is not an option right now. – Mike Feltman Nov 02 '16 at 13:41
  • 2
    The upper-case naming scheme for classes and methods really gets under my skin. –  Nov 02 '16 at 13:52
  • 1
    Is the CS file truly in the same Project/assembly? I don't think a VB project will compile a cs file. Check the build action on your CS file. If its not set to compile that's your issue. If your CS is in a separate project that's been added I believe there is some configuration that needs to be done to make sure ASP.net MVC spans your external libraries to look for controllers. http://stackoverflow.com/questions/7560005/how-to-register-a-controller-into-asp-net-mvc-when-the-controller-class-is-in-a – Bearcat9425 Nov 02 '16 at 14:03
  • @Bearcat9425 thank you! The build action was set to content. The explains everything. Unfortunately when I change it to compile, .NET tries to compile it as VB and doesn't get too far. It looks like this approach is a no-go. – Mike Feltman Nov 02 '16 at 14:13
  • You could add the C# as a separate assembly and then utilize the the second statement of my comment to bring it into the VB.Net project and have ASP.net MVC Scan your assembly for controllers, this could be done with mixed match languages I believe. If you are looking to migrate your project over to C# – Bearcat9425 Nov 02 '16 at 14:38
  • Thanks. I think we'd probably be better off just migrating everything. Going with work arounds/temporary solutions will just create technical debt. 90% of the code in the project is wizard generated controller code because most of the focus has been on the front-end thus far. – Mike Feltman Nov 02 '16 at 14:46
  • I would agree, just offering a solution for temp migration glad your issue is resolved! – Bearcat9425 Nov 02 '16 at 14:47

0 Answers0