5

I have 5 to 6 projects. Project A and B use a same file via Linked File. Now, if I use this class in Razor I will get,

The call is ambiguous between the following methods or properties:

Because Razor views reference all the dlls in bin. It is referencing the same class from Project A and B. How to tell the Razor during compilation use Project A and not Project B?

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322
  • Why don't you use signatures? At least don't use linked files and separate them to avoid overlapping! https://msdn.microsoft.com/en-us/library/aa691131%28v=vs.71%29.aspx – Amirhossein Mehrvarzi Feb 21 '15 at 20:37

4 Answers4

6

You should not use Linked Files when including the assembly too. Why do you need the referenced class twice? There is no point in that.

You have to put that file in a separate project and reference that one in A, B and your MVC project. This makes you don't need the linked files any more.

Another way is to get the assembly and from this assembly, get the type using reflection and then call the method.

Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
0

I know it's kind a tricky answer but you can add another class in one of your two projects and this class will just inherit from your shared class.

Then you can use this new class in the Razor without any problems

Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
-1

You should use the full namespace

Solution.ProjectA.MyClass
Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
-1

ASP.NET Razor Views allow you to use using statements just like you would in a normal cs class. You just need to add the @ symbol

@using MyNamespace.ProjectA

It will work the same as a cs class.

Robert
  • 4,306
  • 11
  • 45
  • 95
  • 1
    I am talking about same class with same namespace. In short I need extern alias http://stackoverflow.com/questions/4759726/net-multiple-libraries-with-the-same-namespace-referencing – Imran Qadir Baksh - Baloch Feb 18 '15 at 12:20