Search code examples
vb.netmicrosoft-graph-apimicrosoft-graph-sdkscase-sensitivecase-insensitive

Case sensitive in VB.NET


I have a project in VB.NET where I have installed the Microsoft.Graph NuGet package (v5.58.0). This package contains two classes with nearly the same name, differing only by one capital letter: PlannerChecklistItem and PlannerCheckListItem. In C#, I can work with this without any problem, but in VB.NET (which is case-insensitive) it throws the following error:

'PlannerChecklistItem' is ambiguous in 'Microsoft.Graph.Models' namespace

The error occurs as soon as you use the class:

Dim checklistItem As New PlannerChecklistItem 

Is there any way to make VB.NET case-sensitive for this line? Is there a workaround to use this package in VB.NET?

I have noticed that PlannerCheckListItem (with a capital "L") is marked as obsolete. Another approach could be to instruct VB.NET to ignore obsolete classes. Is that possible?

One potential solution could be to create a separate project in C# and wrap PlannerChecklistItem in a new class, then use that class in VB.NET. However, I would prefer a workaround with less impact than mixing C# and VB.NET in the same solution.

I have seen these two questions, but neither of them provides a solid solution to my problem, beyond creating a C# project in the same solution as my existing VB project (and that's precisely what I want to avoid): Dealing with case sensitive name collisions in VB.net How do I handle case sensitive classes and methods from a c# web service in my VB.net app


Solution

  • I have found a solution with reflection:

    Dim nameOfPlannerChecklistItem As String = "Microsoft.Graph.Models.PlannerChecklistItem, Microsoft.Graph"
    Dim typeOfPlannerChecklistItem As Type = Type.GetType(nameOfPlannerChecklistItem)
    Dim checklistItem As Object = Activator.CreateInstance(typeOfPlannerChecklistItem)
    

    I guess Microsoft will fix the bug, but meanwhile this is a valid workaround