How do I treat missing namespace warning as an error? - vb.net

Can someone please help me treat the following warning as an error? One of our dev setups (a build machine) treats this issue as an error, others (developers' machines) as a warning. I can't seem to find anything online regarding this.
Namespace or type specified in the Imports
'Your.Nonexistent.Namespace' doesn't contain any public member or
cannot be found. Make sure the namespace or the type is defined and
contains at least one public member. Make sure the imported element
name doesn't use any aliases. C:\Yourproject\yourClass.vb
Thanks for any help.

On the Project Properties page Compile tab there is a checkbox labled Treat all warnings as errors. this w

Related

DocumentFormat for OpenXML

I'm trying to create an Excel file to save using OpenXML and I've found some guidelines on Microsoft website, talking about declaration of OpenXML through importing modules. I added at the beginning of the code:
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Spreadsheet
Imports DocumentFormat.OpenXml.Packaging
I'm having back three warnings, each per line: BC40056 Namespace or type specified in the Imports 'DocumentFormat.OpenXml' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. Besides, I'm also having issues while compiling the code itself, because every time I recall DocumentFormat, I receive back an error about "not declared" variable. Which could be the problem? Thanks in advance all are gonna answer me.

Cannot import Quartz.NET library for VB

I have downloaded Quartz.NET and put it into the folder of my project. And I have also added Quartz.NET\bin\Release\Quartz\net452\Quartz.dll as reference. The import statements are:
Imports Quartz
Imports Quartz.Impl
(I just followed what I found in online tutorials and examples)
However, compiler error message appears for each import statement when I run the code:
Namespace or type specified in the Imports 'Quartz' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
I have tried to remove the reference and add it again. It's fine before running, but error still occurred during compilation. Can anyone find out why does the error happen?

Why does import need the project name and not just the object?

It took me a while to even understand the problem I'm about to describe, so please let me know if the description is confusing...
I have an object called "cProp" that defines a number of sub-classes. To refer to these classes in other files in the project, I have to do something like...
Dim cp = New cProp.InflationRow()
I understand why this is; since the InflationRow is "inside" the cProp, I need to tell it where to find it. Fine.
But this, of course, gets tedious, so sometimes you want to fix it...
Imports cProp
Why doesn't that work? Why do I have to...
Imports ProjectName.cProp
You might wonder why I care, but these files are used in numerous projects with different names. So if I use Imports I have to change the project name in a bunch of places. I am aware that Namespace is likely the solution I want, right?
My confusion stems from the fact that the compiler can figure out just fine which cProp (which is the only one) I'm referring to in the code, so why not in the Imports? I think I'm missing something fundamental here.
It's because your project has a root namespace - you can see this in your project properties. You can delete this in the project properties - this will result in allowing you to simply use the class name from another project. However, namespaces are a good way to organize your classes. In VB, the project defaults to having a root namespace, which you don't see in your code files.
Within your project, since it seems to be all within the same root namespace, you don't have to qualify with the root namespace for code within the root namespace. The "Imports" statements are not within a namespace (only types can be within namespaces) - that's why you have to provide the full qualification there.

System.Data.Function is not available in this context because it is 'Friend'

I'm currently trying to create a NEWID() function in my DataContext in LINQ using the solution here, however, when adding the partial class to my DataContext.vb or a separate DataContextPartial.vb, I get the error System.Data.Function is not available in this context because it is 'Friend'.
I've come across this when accessing data types before and that was in easy fix of setting it to Public, but I'm not sure where the properties for function could be or how to change them.
The code I have is converted to VB.NET from the C# in the linked answer above:
Partial Public Class CMSModelDataContext
<[Function](Name:="NEWID", IsComposable:=True)> _
Public Function Random() As Guid
Throw New NotImplementedException()
End Function
End Class
Thanks for any help in advance.
I can't remember offhand whether VB applies the "Attribute" suffix automatically. Try this instead:
<FunctionAttribute(Name:="NEWID", IsComposable:=True)>
... and make sure you have an import for System.Data.Linq.Mapping.
EDIT: It looks like VB does apply the Attribute suffix, so I suspect you were missing an import or a reference. However, specifying FunctionAttribute explicitly will at least help you to verify this by removing the "false positive" of System.Data.Function.
I believe you should
Import System.Data.Linq.Mapping
because FunctionAttribute resides there.
You didn't import the namespace, and compiler went to look for the class in the wrong direction. Trying its best and seeing that you have imported System.Data, compiler assumed you want to use System.Data.Function which is an internal (Friend) class in System.Data.dll assembly, hence the error.
One can wonder what exactly is the purpose of this error message. If the class isn't accessible anyway, why even bothering to tell about it? I think the reason is you could've referenced your own assembly forgetting to make some of types Public. It makes sense that compiler warns you that it sees the class but you just can't use it. It also makes sense applying same rules to all references, including framework libraries, although obviously you can't modify anything in there.
I would argue that FunctionAttribute is not a particularly good choice of name because it's begging for wrong namespace imports and related confusion.

Problem getting type to appear in intellisense from project reference

I'm getting a compiler error saying that "Acme.Business.User" is not defined.
I have a class library project called "Acme.Business" that has "Acme.Business" as the assembly name and root namespace as well. None of the classes use the "Namespace" keyword, so they all should exist in the namespace "Acme.Business".
I also have a class library project called "Acme.Web" that has a project reference to "Acme.Business". Again "Acme.Web" is the project name, assembly name, and root namespace.
Here's the weird part. If I add a class to "Acme.Web" I can type "Imports Acme." at the top and see both namespaces appear in intellisense like you'd expect, but if I try to do "Dim x as New Acme.Business.User" then "Business" doesn't show up in intellisense and I get an error saying "Acme.Business.User" is not defined.
I can't see what I'm doing wrong! Please help. Thanks.
I think you may be misunderstanding how project default namespaces work. The default namespace is a project file setting that simply tells Visual Studio what namespace to add to each file when you add a new class file to the project. If you have removed all of these namespaces from the code files then your types do not exist in that namespace.
This means that all of your types in the Acme.Business assembly live in the global namespace which is probably not what you want. In order to get the desired behavior you will need to add the namespaces back into your code files as that is the only way the compiler will create type names with that namespace.
OK, I figured out that the behavior I was seeing was because I was declaring namespaces within the code in Acme.Web the way I was used to in C# which is to fully qualify it, ie. Namespace Acme.Web.UI.WebControls. I didn't realize that in VB.NET it's building on top of what was specified for the root namespace. I removed the portion that was specified in the "root namespace" setting of my project and it started working. So my namespaces in code for Acme.Web now look like Namespace UI.WebControls.