Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
    
Why don't you use signatures? At least don't use linked files and separate them to avoid overlapping! msdn.microsoft.com/en-us/library/aa691131%28v=vs.71%29.aspx –  AmirHossein Mehrvarzi Feb 21 at 20:37

4 Answers 4

up vote 6 down vote accepted
+50

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.

share|improve this answer
    
Talking about Razor –  user960567 May 4 '14 at 9:46
    
What makes Razor different then every other .NET project? –  Patrick Hofman May 4 '14 at 9:54
    
When compiling Razor views, it will reference all the dlls in bin folder. –  user960567 May 4 '14 at 10:34
    
Still, you include a reference and a class in linked file. That will never work. –  Patrick Hofman May 4 '14 at 11:35
1  
@user960567 Patrick Hofman is right, create a project and put a class to communicate with this linked file and let the project a and b to reference this new project c, this way you will get rid from the problem –  Hadi Hassan Feb 24 at 10:05

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

share|improve this answer

You should use the full namespace

Solution.ProjectA.MyClass
share|improve this answer
1  
No. This will not work –  user960567 May 4 '14 at 9:25

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.

share|improve this answer
1  
I am talking about same class with same namespace. In short I need extern alias stackoverflow.com/questions/4759726/… –  user960567 Feb 18 at 12:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.