Ambiguous class Reference when using Linked File in Different Projects in Razor?

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?

Upvotes: 5

Views: 951

Answers (4)

Patrick Hofman
Patrick Hofman

Reputation: 156938

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.

Upvotes: 6

Wahid Bitar
Wahid Bitar

Reputation: 14074

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

Upvotes: 0

Robert
Robert

Reputation: 4406

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.

Upvotes: -1

Wahid Bitar
Wahid Bitar

Reputation: 14074

You should use the full namespace

Solution.ProjectA.MyClass

Upvotes: -1

Related Questions