简体   繁体   中英

Difference in the properties for the same dll in c#.net and vb.net

I am adding a dll for my project. My project is in vb.net and dll is written in c#.net. When I add this to a vb.net project the properties that are available are different (less in number) to the properties that are available if the same dll is added to ac# project.

Object Browser view when added to a VB.Net Project 在此输入图像描述

Object Browser view when added to ac# project 添加到c#项目时的对象浏览器视图

If you see in c# view you can access properties like "hits" and "facets" which are not accessible in vb.net.

Can anyone please help me understand this issue.

There are differences between VB.NET and C#. Make sure you compile your C# dll with the assembly attribute CLSCompliant set to true so your compiler can determine if all your publics are compatible to the other .NET languages.

To clarify my situation I am using a dll downloaded from github. When I downloaded the source code from github I found out that it is not CLSComplaint. When I changed the property name and added DataMember attribute (for jsonserilzation) all the properties are available in vb.net project as well, but the problem I will be facing is merging of the code changes to any updates in the particular class library in original version to the CLSComplaint one which I don't want to commit to GitHub until I speak with author.

As a work around I added GetHitCount(CLSComplaint property name)

public int GetHitCount
{
    get { return hits.total;}
}

this exposes the "hits" property which is not available when the dll is added to vb.net project.

It's likely that "hits" and "facets" in the C# project have members in the class that have the same name, but different case. This is a very common issue for VB projects referencing C# dlls, and it also will result in the C# dll not being CLS Compliant. VB is case-insensitive, so it cannot determine which "hits" is being needed if there also is a "Hits" member - as a result VB will not display either member.

You can still call "hits" and "facets", but you will need to use "InvokeMember" to do this (using reflection).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM