VB.NET: Ambiguous class name error when no ambiguity exists

半城伤御伤魂 提交于 2019-12-23 12:46:05

问题


A client of ours reported that when trying to use our .NET .DLL in VB.NET they receive the error:

error BC31429: 'OurClass' is ambiguous because multiple kinds of members with this name exist in namespace 'our.company.nspace'

I've also been able to reproduce the error with a dummy project containing the single line of

Dim x as our.company.nspace.OurClass

Normally this is because there are several types with names differing only in case. But in this case there is no such ambiguity. OurClass is a unique name not only in the specific namespace but in the whole assembly and any other assemblies referenced by the project. Reflector also shows this. There are also no class members with the same name, also verified by Reflector.

Also a weird thing is that the error wasn't there immediately after I created the dummy project, and then it suddenly appeared and now it doens't go away anymore. In fact I didn't even change anything between the two recompiles from which the first one worked, and the second didn't.

So... what gives?

(Note: the .DLL uses and references vjslib (J#), if that is of any relevance)


回答1:


Have you tried using the Global. prefix? e.g.

Dim x as Global.our.company.nspace.OurClass

See http://msdn.microsoft.com/en-us/library/k701czy1(VS.90).aspx




回答2:


I've had this issue when deploying a web app before. I wasn't getting the error in my development environment, but when I tried to deploy it to a test server I got the ambiguous namespace error. I had to delete all of the DLLs from the bin folder and then redeploy the application.

It sounds like it could be a reference issue. Perhaps the client just needs to remove and re-add the reference to your DLL and then do a Rebuild on their solution?




回答3:


Found the issue. There are two classes with duplicate names one lowercase (marked as "obsolete") and one uppercase but both left in the code. Not CLS compliant obviously and blows up VB.Net which is not case sensitive.

generate and Generate

generateAsync and GenerateAsync

Solution for today is to download from GitHub, remove the lowercase offenders, recompile and manually add to project at least until an updated fix is posted on their end.



来源:https://stackoverflow.com/questions/3491801/vb-net-ambiguous-class-name-error-when-no-ambiguity-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!