I'm trying to create a manager class to use with my charting tool, the problem is the tool I use, uses the same names for both a 3d and 2d charts which is resulting in ambiguous reference when I try to add the 2d library.. any ideas how best to resolve this?
For example,
using tool.2dChartLib;
using tool.3dChartLib;
BorderStyle is a member of both of these
I've tried casting the areas where I use BorderStyle. I suppose it could work if i just reference tool but then that would mean I'd have hundreds of tool.class lines instead of class
If the types with the same name exist in both namespaces, you have a couple of options:
1) If the number of types is small, create an alias for that type:
using BorderStyle3d = tool.3dChartLib.BorderStyle;
2) If the number of types is large, you can create an alias for the namespace:
using t3d = tool.3dChartLib;
Then in your code...
t3d.BorderStyle
You can use full type names, or create aliases:
using 2dBorderStyle = tool.2dChartLib.BorderStyle;
Use namespace alias
using twoDimensionLib = tool.2dChartLib;
using threeDimensionLib tool.3dChartLib;
I had similar problem that the class had ambiguous reference for the SAME namespace, so I deleted a specific Project (under Dependencies/{my.prj.name}.API) which had duplicated reference.
After that I referenced Project back with using of CTRL+.
Hope it'll work for you.
New reference of specific class
Related
I am currently building an e-commerce application and it will be integrated with Epicor10. I am using C# to integrate e-commerce and Epicor; So now I'm having trouble using a library class from Epicor10 to use ARInvSelDataSet and set a value object ARInvSel
Following is my code:
ARInvSelDataSet ArDataSet = new ARInvSelDataSet();
ArDataSet.ARInvSel[0].InvoiceNum = Invoice.InvoiceNum;
First, you must either add a using directive to the top of your code:
using Erp.Tablesets;
...or fully qualify ARInvSelDataSet as Erp.Tablesets.ARInvSelDataSet
Second, you must add a reference to the contract you are using that contains the definition for the custom dataset type. I couldn't find the particular contract that holds this, but I'm assuming if you know that this specific type exists, you must have seen it within the context of the contract.
I'm trying to implement a common attribute type and corresponding enum type to be included in AssemblyInfo.cs for every project, for use as metadata. All projects in my solution will require the attribute.
I have created a Visual Studio 2015 Shared Project and included these types.
Subsequently, I referenced the Shared Project in some base level assemblies, which contain no interdependencies. However, if I include two or more of these assemblies as references in larger projects, I receive the "type exists in both X assembly and Y assembly" (CS0433)
Am I implementing the Shared Project incorrectly? Is this a bad approach to solve the stated task?
This happens when you have two using statements at the top, which contain classes with identical names. There are two possible ways to deal with this.
Remove one (or both) using references and type the class names and types long-hand.
Example:
//using System.Data.SqlClient;
//using System.Data.OleDbClient;
var p1 = new System.Data.SqlClient.Parameter();
var p2 = new System.Data.OleDbClient.Parameter();
or
Alias both using references. You will still have to qualify your class names, but you can use the alias instead of full long-hand.
Example:
using Db1 = System.Data.SqlClient;
using Db2 = System.Data.OleDbClient;
var p1 = new Db1.Parameter();
var p2 = new Db2.Parameter();
I seem to have stumbled upon an answer. I had my Shared Project types declared under their own namespaces.
When I removed the namespace block from the code, the code compiled correctly.
I'm not sure if this a legitimate fix to the problem, but it seems to make the compiler happy.
In C#, I want to reference Microsoft.Kinect (v1.8) and Microsoft.Kinect (v2.0) in the same project. They are different DLLs but use the same namespace. I am able to reference them both with a renaming hack in the .csproj file (by calling them "Microsoft.Kinectv1" a "Microsoft.Kinectv2" respectively.
The problem still remains of how to specifically reference one or the other in code though, since they both have the same namespace. Visual Studio notices that the some class is used in both asseblies (v1.8 and v2.0) but I don't know how to specify one version or the other in code. I have read several posts about this but none of these posts went as far as showing specifically how to solve this issue. How would this be done?
In the properties window give each assembly a different alias (lets say you named them: assem01 and assem02);
At the TOP of the file you want to use the same namespaces write:
extern alias assem01;
extern alias assem02;
Note: These lines MUST be written before any other code in the file.
Now you can access the same namespace from both assemblies, for example:
var c1 = new assem01::ns1.ns2.myClass();
var c2 = new assem02::ns1.ns2.myClass();
For convenience, you may wish to give some aliases to the namespaces too, for example:
using assem01_ns2 = assem01::ns1.ns2;
using assem02_ns2 = assem01::ns1.ns2;
var c1 = new assem01_ns2.myClass();
var c2 = new assem02_ns2.myClass();
Hope this was helpful.
In a visual studio 2008 solution, I have two versions of the same class in two different namespaces.
In VB, if I do this:
imports MyNamespace
' ...
dim x as DuplicatedClass = new DuplicatedClass()
it uses MyNamespace.DuplicatedClass instead of the globally-namespaced DuplicatedClass. Meanwhile, in C#, doing this:
using MyNamespace;
// ...
DuplicatedClass x = new DuplicatedClass();
uses the globally-namespaced DuplicatedClass. To use the other version, I have to use MyNamespace.DuplicatedClass.
I realize this is a problematic setup, but I can't change it. Is there a way to prevent C# from seeing the globally namespaced class, or to specifically un-load it, or...? Given how many classes are in the global namespace, being forced to choose the namespace every time could get pretty time-costly.
Perhaps the best you could do is create a using alias:
//create alias
using defDuplicatedClass = MyNamespace.DuplicatedClass;
defDuplicatedClass x = new defDuplicatedClass();
The alias is file scoped. So you'd have to repeat it at the top of each file as needed, but perhaps that is better than repeating a namespace with every occurance of DuplicatedClass.
I have a namespace conflict between two referenced assemblies:
i.e., I'm referencing Foo.A.Foo and Foo.Bar, so when I say I want Foo.Bar.Control, VS is trying to find Foo.A.Foo.Bar.Control
I can twiddle the Designer.cs code by adding new global:Foo.Bar.Control(), but as soon as I change anything, VS switches back.
I know there's something about adding aliases directly to the reference, I've tried but haven't managed to find the right combination (inline alias, using alias, reference alias).
Help?
"extern alias" may be what you mean, but I'm not sure what the designer will do with it, unfortunately...
I'm not even sure that's what you're after though - that's normally for two types from different assemblies with the same name.
You can write namespace aliases with a using directive, e.g.
using FooControl = Foo.Bar.Control;
but again, the designer is going to rewrite your code...
OK, this isn't the answer, but it's what I found for a workaround:
namespace FooBar
{
class FooBarControlHack : Foo.Bar.Control { }
}
So I can do the following in the Designer.cs :
this.fooBarControl = new FooBar.FoorBarControlHack();