Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Oct 04, 2011 @ 16:49
    Simon Dingley
    0

    Razor Error about Class existing in 2 locations

    I am trying to call a custom method from an existing class library in a Razor macro but it keeps throwing the below exception:

    The type 'MyClient.BusinessLogic.Umbraco.Library' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\c9f003be\1af5c642\App_Code.hfeopvhj.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\c9f003be\1af5c642\assembly\dl3\6198c785\fa910c4e_9882cc01\MyClient.BusinessLogic.DLL

    The macro contains the following code:

    @using MyClient.BusinessLogic.Umbraco;
    
    @{
    <ul id="event-series-schedule" class="ui-corner-all alt">
        @foreach(var evt in Model.Children)
        {
            <li>
                <h3>@evt.Name</h3>
                <p>
                    @evt.EventStartDate.ToString("MMMM dd, yyyy") - @evt.EventEndDate.ToString("MMMM dd, yyyy")
                    <br />
                    @Model.NodeById(evt.eventVenue).Name
                    <br /><br />
                    Buy-in: @Library.GetCurrencySymbol(@evt.eventCurrency) @evt.eventBuyIn @evt.eventCurrency @evt.eventEntryFee 
                </p>
            </li>
        }
    </ul>
    }

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Oct 04, 2011 @ 16:52
    Sebastiaan Janssen
    0

    Umbraco also has an Umbraco.Library class, so it's getting confused. Solutions:

    Don't use Library as your class name, or refer to @Library as @MyClient.BusinessLogic.Umbraco.Library, OR alias it like so:

    @using Lib =  MyClient.BusinessLogic.Umbraco; and then use @Lib.GetCurrencySymbol 

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Oct 04, 2011 @ 16:56
    Simon Dingley
    0

    Thanks Sebastiaan. I have already tried @MyClient.BusinessLogic.Umbraco.Library with no success, the same error occurs. The exception is complaining about the fully qualified class name? I also have no success with @using Lib =  MyClient.BusinessLogic.Umbraco.Library;

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Oct 04, 2011 @ 17:03
    Sebastiaan Janssen
    0

    Okay, I don't get this problem, here is my class (in a seperate dll, but that shouldn't matter):

    namespace MyClient.Businesslogic.Umbraco
    {
        public class Library
        {
            public static string GetCurrencySymbol()
            {
                return "test";
            }
        }
    }

    And both of these Razor calls work:

    @using Lib = MyClient.Businesslogic.Umbraco;
    
    @MindBus.Businesslogic.Umbraco.Library.GetCurrencySymbol()
    @Lib.Library.GetCurrencySymbol()

    So I'm curious what's different in your setup then..

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Oct 04, 2011 @ 17:10
    Simon Dingley
    0

    My class is in a seperate assembly also, the only real difference that I can see between your example and mine is the addition of the XsltExtension attribute on my class as follows:

    [XsltExtension(Namespace = "MyClient")]

    As you already know my patience with Razor runs pretty low as it seems to cause me one issue after another just to achieve apparently simple things. I am sure if I ever had the time to invest in overcoming issues like this I may perhaps like it but for now I find myself time and time again having to go back to XSLT just to get things done.

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Oct 04, 2011 @ 17:15
    Sebastiaan Janssen
    0

    Ha, Razor has the exact opposite effect on me! :-) 

    Are is there any other projects in your solution that use Umbraco.Library in their namespace?
    Does your XSLT extension work? (in XSLT of course).
    For this to work, the method GetCurrencySymbol has to be static, is it?

    Try (in your Razor file) to alias the Library to Lib and just use intellisense and see wat happens. So @Lib. [CTRL+Period] should give you Library as a choice, another [CTRL+Period] should add GetCurrencySymbol as an option. 

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Oct 04, 2011 @ 21:28
    Simon Dingley
    0

    No other projects in solution using Umbraco.Library in their namespace.

    Yes my XSLT Extension works fine and is static :p

    Using Intellisense I get the correct Libary in the correct namespace and can therefore choose the GetCurrencySymbol) method.

  • Rodion Novoselov 694 posts 859 karma points
    Oct 04, 2011 @ 21:54
    Rodion Novoselov
    0

    1) First of all I would try and clear the folder with the compiled ASP.NET application (i.e. Temporary ASP.NET Files).

    2) Try to precompile your site with aspnet_compile (it can be usefull since you will catch such errors immediately instead of in runtime).

    3) Also make sure that nothing is duplicated in referenced dlls and the App_Code folder (yeh, it sounds a bit silly, but actually I have already seen such a situation several times - it happens because of wrong project/build settings. If something is placed to App_Code folder then it should be excluded from project compilation since it's supposed to be compiled in runtime by ASP.NET itself).

Please Sign in or register to post replies

Write your reply to:

Draft