3

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 a c# project.

Object Browser view when added to a VB.Net Project enter image description here

Object Browser view when added to a c# project Object Browser view when added to a c# project

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.

dittu
  • 78
  • 1
  • 6
  • 1
    Might your DLL be out of date? Maybe hits and facets have been added recently and you are using a DLL in your VB project which was compiled before hand? – JMK Jun 17 '13 at 12:09
  • 2
    How are `hits` and `facets` defined? Is there anything unusual about them? – Tim S. Jun 17 '13 at 12:11
  • 1
    Some types, e.g. `uint`, are not available to VB. – Matthew Watson Jun 17 '13 at 12:16
  • 1
    Capitalize your property names :) – gustavodidomenico Jun 17 '13 at 12:18
  • @MatthewWatson - Can you please expand on your comment. VB allows `Dim i As UInteger = 42` for example. – Chris Dunaway Jun 17 '13 at 13:21
  • @dittu - Do you, perhaps, have "Hide Advanced Members" turned on in VS for VB.Net? – Chris Dunaway Jun 17 '13 at 13:23
  • @ChrisDunaway I tried turning of Hide Advanced Members and it didn't help. I downloaded the source code for the above mentioned dll from github and I am trying to make it CLS-complaint by changing the property names. – dittu Jun 17 '13 at 13:57
  • @dittu - You won't be able to make a reference that has a `uint` propery CLS compliant. This is because `uint` is of the type `System.Uint32` which is not CLS compliant. The answer to your question is to use `System.Uint32` in your C# code. – Security Hound Jun 17 '13 at 14:15
  • @Ramhound There are no unsigned integers. – dittu Jun 17 '13 at 14:43
  • @dittu - Yes...There is actually http://stackoverflow.com/questions/1561557/what-is-the-uint32-data-type-in-visual-basic-net?rq=1 and http://msdn.microsoft.com/en-us/library/system.uint32.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 – Security Hound Jun 17 '13 at 14:51
  • @ChrisDunaway What I really meant was that `uint` cannot be used by code that requires CLS-Compliance, but I guess if VB has the same type but with a different name, it should be able to use it. – Matthew Watson Jun 17 '13 at 14:57
  • @MatthewWatson - There are CLS alternatives documented by MSDN. `System.Int64` would be the CLS compliant alternative to `System.UInt32` and `Decmial` would be the alternative to `System.UInt64` – Security Hound Jun 17 '13 at 15:03

3 Answers3

6

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.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • This answer does not make a great deal of sense. VB.NET and C# generate the same CL code when compiled – Security Hound Jun 17 '13 at 13:01
  • @Ramhound, what would you expect VB to do with a C# uint, not having an unsigned int type of it's own? – nvoigt Jun 17 '13 at 13:23
  • You would just use `UInt32`. **Int32 and int are exactly the same value type.** I am going to issue a downvote for the first sentence. It should be stated that neither `Uint32` nor `uint` are CLS compliant. – Security Hound Jun 17 '13 at 14:07
  • -1. .NET is not .NET? What is it then? If `a != a`, we got a major logical problem here. :) – Victor Zakharov Jun 17 '13 at 14:09
  • @Ramhound I changed my first sentence. I'm not here to argue about our differing understanding of english as a means to transport fun. – nvoigt Jun 17 '13 at 14:31
  • @Neolisk I changed my first sentence. I'm not here to argue about our differing understanding of english as a means to transport fun. – nvoigt Jun 17 '13 at 14:31
0

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.

dittu
  • 78
  • 1
  • 6
  • If you want a CLS compliant unsigned integer then you need to use http://msdn.microsoft.com/en-us/library/system.int64.aspx instead of the unsigned integer the original code used. Your accepted answer is actually wrong. As I pointed out VB.NET and C# are compiled into the same code ( when CLS code is used of course ). – Security Hound Jun 17 '13 at 14:59
  • @Ramhound all the integers in the particular class I am looking into are System.Int32 type there are no unsigned(Uint32 types). I might have misunderstood your comment. Let me know if I am wrong. – dittu Jun 17 '13 at 15:35
  • I could have sworn your original question was asking about two properties that were unsigned integers. – Security Hound Jun 17 '13 at 15:53
0

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).

Dave Doknjas
  • 6,394
  • 1
  • 15
  • 28