Object in ProjectReference not accessible when using 'Import' - c#

In a simple project i want to reference objects from a webreference added to another c# library.
The Webreference is called QServices The default namespace is set as below
What seems to work is the following code:
Taskworkflow.SI.QServices.Record[] querysResult = new Taskworkflow.SI.QServices.Record[0];
yet when i import the Taskworkflow.SI - namespace, i keep on getting errors:
using TaskWorkflow.SI;
....
QServices.Record[] querysResult = new QServices.Record[0];
This results in the error:
The type or namespace name 'QServices' could not be found (are you missing a using directive or an assembly reference?)
Could someone clarify this for me?
Thank you for your time.
Note: QServices do only exist inside TaskWorkflow.SI. They do not have any occurences in other projects nor do they have any classes/namespaces/objects that share the name.

I strongly suspect that for whatever reason, you're ending up with a namespace called QServices declared in the TaskWorkflow.SI namespace. So actually you want:
using TaskWorkflow.SI.QServices;
....
Record[] querysResult = new Record[0];
Or you could explicitly alias it:
using QServices = TaskWorkflow.SI.QServices;
....
QServices.Record[] querysResult = new QServices.Record[0];

Related

Unable to reference a namespace in another assembly when it partially matches one in the current assembly

I have a project of namespace SpaceCats.Planet.Types that has a class called MajorTomCat.cs
My test project namespace is Test.Fiddlesticks
In my test project, there is a namespace Test.Fiddlesticks.SpaceCats which is generated automatically from a WCF service reference
When I do MajorTomCat cat = new MajorTomCat(), it says it cannot find MajorTomCat.
I try to put it explicitly:
SpaceCats.Planet.Types.MajorTomCat cat;
But it still can't find it. Hovering over it, it says
The type or namespace Planet does not exist in the namespace Test.Fiddlesticks.SpaceCats.
It appears to be looking in the wrong SpaceCats namespace.
I can't figure out how to force it to look in the root.
Any ideas?

The type or namespace name 'VibrationDevice' could not be found

I try to implement vibration in my UWP app by following the example from the VibrationDevice API reference. I have a new empty project with the following code:
using Windows.Phone.Devices.Notification;
...
if (ApiInformation.IsTypePresent("Windows.Phone.Devices.Notifications.VibrationDevice"))
{
VibrationDevice testVibrationDevice = VibrationDevice.GetDefault();
testVibrationDevice.Vibrate(TimeSpan.FromSeconds(3));
}
This code throws the following exception
The type or namespace name 'VibrationDevice' could not be found (are you missing a using directive or an assembly reference?)
I have searched for someone with the same problem but I have not found anything similar and don't really know how to solve this.
What am I missing?
EDIT: As Hans Passant pointed out in the comments I had forgot to add the Mobile Extension. Now everything works as it should.
Looks like you just mistyped the namespace string.
if
(ApiInformation.IsTypePresent("Windows.Phone.Devices.Notifications.VibrationDevice"))

Type or Namespace Error

I have two references in my application. In the BAL code i am able to use the namespace "using TestDAL;"
But I am not being able to use the namespace of BAL in my .cs page. This is the error i get,
CS0246: The type or namespace name 'TestBAL' could not be found (are
you missing a using directive or an assembly reference?)
And one thing in my bin folder too I only have the TestDAL.dll file. How do I insert TestBAL.dll file?
Can anyone help me with what can be possible reason?
Thanks in Advance,
Try this:
Then, click browse and add your .dll file:
That should help you, if not please leave some feedback.
You could also try using alias for your namespace like this:
using namespaceAlias = TestBAL;
Create object of TestBAL objBAL = new TestBAL(); in your cs page. Check out, This codes gives any error or not.

using namespace in C# from CLI/C++ class

This might be a C#-noob question...
Assume I have the following CLI/C++ header:
namespace DotNet {
namespace V1 {
namespace X {
public ref class AClass {
public:
AClass() {}
void foo() {}
static void bar() {}
};
}
}
}
Then from C# I do the following:
using DotNet;
V1.X.AClass a = new V1.X.AClass();
I get:
Program.cs(18,7): error CS0246: The type or namespace name 'V1' could
not be found (are you missing a using directive or an assembly
reference?)
Same with:
using DotNet.V1;
X.AClass a = new X.AClass();
Program.cs(18,7): error CS0246: The type or namespace name 'X' could
not be found (are you missing a using directive or an assembly
reference?)
What works is:
DotNet.V1.X.AClass a = new DotNet.V1.X.AClass();
Or
using DotNet.V1.X;
AClass a = new AClass();
So either I have to use the full namespace path, or I have to open all of the path to access the class. Is there anything I can do about this?
I would like to be able to open only a part of it.
So either I have to use the full namespace path, or I have to open all of the path to access the class.
Yes.
Is there anything I can do about this?
Not that I'm aware of. Why would you not just want a using directive for the whole namespace? Isn't that the simplest approach?
Note that this has nothing to do with C++/CLI. The same is true whatever the source language is - so you can see it with C# as well:
namespace DotNet.V1.X
{
public class AClass {}
}
As Jon Skeet stated you have to include the full namespace in either the using statement or each time you reference it in code. I recommend just placing the full namespace in the using statement.
You can, however, achieve that syntax with a using alias, but it does not add anything of value outside of syntax.
using V1 = DotNet.V1;
...
V1.X.AClass a = new V1.X.AClass();
Also if you are using C# version 3.0 or higher the var keyword will only require you type out the full namespace on the right side of the assignment.
var a = new DotNet.V1.X.AClass();

RazorEngine Razor.Parse(...) throws exception about ServiceStack and Markdown?

I ran this simple example from the website and I get the error below when it calls Razor.Parse. How can I fix this???
http://razorengine.codeplex.com/
string template = "Hello #Model.Name! Welcome to Razor!";
string result = Razor.Parse(template, new { Name = "World" });
error CS0234: The type or namespace name 'Markdown' does not exist in the namespace 'ServiceStack' (are you missing an assembly reference?)
Not sure why you've linked to http://razorengine.codeplex.com
The 'ServiceStack' error assumes you want to use the Markdown engine in ServiceStack in which case you should be referencing the RazorEngine.dll that comes with ServiceStack not the one in razorengine.codeplex.com if that's what is done here.
I would imagine one of two things has happened. Either in your configuration file, namespaces have been added within the <razorEngine> configuration section, or the AddNamespace method is being called somewhere to include namespace imports in the compiled template.
The net result, is that namespaces are added to the generated class file, but references are missing. RazorEngine will automatically reference any loaded assemblies in the AppDomain.

Categories