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
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;
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.
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.
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).
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:
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
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;
Okay, I don't get this problem, here is my class (in a seperate dll, but that shouldn't matter):
And both of these Razor calls work:
So I'm curious what's different in your setup then..
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:
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.
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.
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.
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).
is working on a reply...