'umbraco.interfaces.INode' does not contain a definition for 'GetCurrent'
Hi. I'm having problems with understanding what's going on in my 6.0.3 umbraco.
Here is the code in some Razor macro:
@using umbraco.NodeFactory @{ var qwe = Node.GetCurrent(); }
I'm getting exception: error CS1061: 'umbraco.interfaces.INode' does not contain a definition for 'GetCurrent' and no extension method 'GetCurrent' accepting a first argument of type 'umbraco.interfaces.INode' could be found (are you missing a using directive or an assembly reference?)
When I type it as var qwe = umbraco.NodeFactory.Node.GetCurrent(); everything works fine. I am wondering, what is going on? Why when I do not specify parent namespace for Node, it's answering me like it's INode?
var is never used to guess variable type. Vice versa, it's resolved into the type when compiling to IL code. I have just tried Node qwe = ... , it changed nothing =)
Here are all usings: @using UCommerce.Api @using UCommerce.EntitiesV2 @using UCommerce.Extensions @using UCommerce.RazorStore.Code.Shop @using UCommerce.Runtime @using umbraco.NodeFactory
But it should not matter, because I have tried it this way: once I remove single using line of umbraco.NodeFactory, I'm getting error: 'umbraco.MacroEngines.BaseContext<T>.Node' is a 'property' but is used like a 'type'.
Strange and yes it should not matter. Have you tried removing the UCommerce refrences Would be intrested to hear of the solution if and when you find it :). Charlie
Not totally sure what the problem is :(. I will have a think. The main thing at the moment is you can still use it i guess. If you do find out please let me know :). Chalrlie
If you're using a razor macro in v6, you don't need to use the Node API, you can just use @Model.Content for a strongly typed content object with intellisense or for a dynamic version, just use @CurrentPage.
I don't know if that's "razor macro" I'm using. It's .cshtml file, located in macroScripts folder, it have a couple of usings and razor markup. In umbraco backend it's in "or script file". In my umbraco settings there's <defaultRenderingEngine>WebForms</defaultRenderingEngine>.
Model have no intellisense in my vs2012. "The name 'CurrentPage' does not exist in the current context", Model.Content gives me.. some variable with text of the main page. If trying to use it instead of var current = umbraco.NodeFactory.Node.GetCurrent();, I'm getting Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Web.HtmlString' does not contain a definition for 'Id'.
Anyway I'm not sure if it's relevant to the topic: why is Node class when referenced without namespaces, acting like it's INode interface? Must be some magic going on.
Right, there lies one problem. What version of umbraco are you using. And where and what is the macro scripts folder? If you are using a .cshtml file. Then you need to change <defaultRenderingEngine>WebForms</defaultRenderingEngine>. to <defaultRenderingEngine>MVC</defaultRenderingEngine>.
In the dll for you project you need to add the umbraco DLLS, found in the bin of the package. Namely Umbraco.dll. This will have the umbraco.nodefactory namespace :). Charlie :)
Like I said in the first post, it's Umbraco 6.0.3. MacroScripts folder is the default one. The one placed in the root of the Umbraco. The one Umbraco is looking for script files for category "or script file". Let's try to be clear: webforms and mvc are different paradigms of programming. Razor, aspx, xslt etc. is markup language, the way to tell compiler what to do. Nothing wrong in coding MVC views in aspx. Actually when Razor markup was very new, MVC used to use aspx views, if I'm not mistaken. As far as I understand, defaultRenderingEngine parameter is in charge of setting default Umbraco templating system. If it's MVC, new templates you create in Umbraco are "views", not webforms pages. You are telling me to use @inherits Umbraco.Web.Mvc.UmbracoTemplatePage in my macro. First of all my project doesn't know the .Mvc namespace part (what dll should I include?) Second thought: my .cshtml file is not umbraco template page! It's not mvc view! It's a macro. A Razor macro from macroScripts folder. I don't think we are heading in right direction at all. Have a look at http://our.umbraco.org/projects/website-utilities/ucommerce , the file I particulary talking about is ~\macroScripts\uCommerce\LeftNavigation.cshtml
>> In the dll for you project you need to add the umbraco DLLS, found in the bin of the package. Namely Umbraco.dll. This will have the umbraco.nodefactory namespace :). Charlie :)
I already have it referenced. That's why I'm able to see umbraco. NodeFactory namespace in my IntelliSense. It doesn't matter for the runtime, though, as by default .cshtml files are not compiled. Take a look at https://bitbucket.org/uCommerce/ucommerce-razor-store , I'm using this visual studio solution. It doesn't matter, though. I just have default .cshtml macro in default macro folder. It's using default umbraco.NodeFactory.Node, and for some reason INode interface is popping somewhere there inbetween. What is happening? - is the question.
Hi Morten. Where should I delete references from? I'm adding new test.cshtml to \macroScripts , it's content is
@using umbraco.NodeFactory
@{
//var current = umbraco.NodeFactory.Node.GetCurrent();
var current = Node.GetCurrent();
}
@current.ToString()
And it is already getting same exception. Razorstore project references are just for convenience when it comes to .cshtml.
It's totally the same on empty 6.1.0-beta Umbraco with just starter kit installed. Clearly not an issue with uCommerce.
Can you please elaborate on how you was able to _use_ var current = Node.GetCurrent(); ? (intellisense always used to say it's fine; runtime is different story)
Hm, I'm not using Visual Studio, or nuget for Umbraco. I just download it from codeplex, and throw it to webmatrix or IIS. And it doesn't have any "references". It just uses whatever it can find in /bin afaik. (maybe have something to do with web.config as well)
So you are saying that in bare console/text VS solution umbraco.NodeFactory library is working as expected. Good to hear.
Here is what happening: even though I do not write it, looks like Macro is automatically inherited from umbraco.MacroEngines.DynamicNodeContext (or from some other class, that's a child to BaseContext<>). This is a guess, but it sounds pretty much right.
'umbraco.interfaces.INode' does not contain a definition for 'GetCurrent'
Hi. I'm having problems with understanding what's going on in my 6.0.3 umbraco.
Here is the code in some Razor macro:
@using umbraco.NodeFactory
@{
var qwe = Node.GetCurrent();
}
I'm getting exception: error CS1061: 'umbraco.interfaces.INode' does not contain a definition for 'GetCurrent' and no extension method 'GetCurrent' accepting a first argument of type 'umbraco.interfaces.INode' could be found (are you missing a using directive or an assembly reference?)
var qwe = umbraco.NodeFactory.Node.GetCurrent();
everything works fine. I am wondering, what is going on? Why when I do not specify parent namespace for Node, it's answering me like it's INode?
Thats strange :/. What other using statements do you have? You should be using Node node and not var. :)
var is never used to guess variable type. Vice versa, it's resolved into the type when compiling to IL code. I have just tried Node qwe = ... , it changed nothing =)
Here are all usings:
@using UCommerce.Api
@using UCommerce.EntitiesV2
@using UCommerce.Extensions
@using UCommerce.RazorStore.Code.Shop
@using UCommerce.Runtime
@using umbraco.NodeFactory
But it should not matter, because I have tried it this way: once I remove single using line of umbraco.NodeFactory, I'm getting error: 'umbraco.MacroEngines.BaseContext<T>.Node' is a 'property' but is used like a 'type'.
Strange and yes it should not matter. Have you tried removing the UCommerce refrences Would be intrested to hear of the solution if and when you find it :). Charlie
Removed all usings except umbraco.NodeFactory, nothing changed.
Not totally sure what the problem is :(. I will have a think. The main thing at the moment is you can still use it i guess. If you do find out please let me know :). Chalrlie
If you're using a razor macro in v6, you don't need to use the Node API, you can just use @Model.Content for a strongly typed content object with intellisense or for a dynamic version, just use @CurrentPage.
Hope that helps!
I don't know if that's "razor macro" I'm using. It's .cshtml file, located in macroScripts folder, it have a couple of usings and razor markup. In umbraco backend it's in "or script file". In my umbraco settings there's <defaultRenderingEngine>WebForms</defaultRenderingEngine>.
Model have no intellisense in my vs2012. "The name 'CurrentPage' does not exist in the current context", Model.Content gives me.. some variable with text of the main page. If trying to use it instead of var current = umbraco.NodeFactory.Node.GetCurrent();, I'm getting Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Web.HtmlString' does not contain a definition for 'Id'.
Anyway I'm not sure if it's relevant to the topic: why is Node class when referenced without namespaces, acting like it's INode interface? Must be some magic going on.
Right, there lies one problem. What version of umbraco are you using. And where and what is the macro scripts folder? If you are using a .cshtml file. Then you need to change <defaultRenderingEngine>WebForms</defaultRenderingEngine>. to <defaultRenderingEngine>MVC</defaultRenderingEngine>.
In the dll for you project you need to add the umbraco DLLS, found in the bin of the package. Namely Umbraco.dll. This will have the umbraco.nodefactory namespace :). Charlie :)
At the very top of your razor file use
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
and then you can do
@Model.Content.GetProperty ... ect ect ect
Like I said in the first post, it's Umbraco 6.0.3. MacroScripts folder is the default one. The one placed in the root of the Umbraco. The one Umbraco is looking for script files for category "or script file". Let's try to be clear: webforms and mvc are different paradigms of programming. Razor, aspx, xslt etc. is markup language, the way to tell compiler what to do. Nothing wrong in coding MVC views in aspx. Actually when Razor markup was very new, MVC used to use aspx views, if I'm not mistaken. As far as I understand, defaultRenderingEngine parameter is in charge of setting default Umbraco templating system. If it's MVC, new templates you create in Umbraco are "views", not webforms pages. You are telling me to use @inherits Umbraco.Web.Mvc.UmbracoTemplatePage in my macro. First of all my project doesn't know the .Mvc namespace part (what dll should I include?) Second thought: my .cshtml file is not umbraco template page! It's not mvc view! It's a macro. A Razor macro from macroScripts folder. I don't think we are heading in right direction at all. Have a look at http://our.umbraco.org/projects/website-utilities/ucommerce , the file I particulary talking about is ~\macroScripts\uCommerce\LeftNavigation.cshtml
>> In the dll for you project you need to add the umbraco DLLS, found in the bin of the package. Namely Umbraco.dll. This will have the umbraco.nodefactory namespace :). Charlie :)
I already have it referenced. That's why I'm able to see umbraco. NodeFactory namespace in my IntelliSense. It doesn't matter for the runtime, though, as by default .cshtml files are not compiled. Take a look at https://bitbucket.org/uCommerce/ucommerce-razor-store , I'm using this visual studio solution. It doesn't matter, though. I just have default .cshtml macro in default macro folder. It's using default umbraco.NodeFactory.Node, and for some reason INode interface is popping somewhere there inbetween. What is happening? - is the question.
OK! I have not seen the macro scripts folder but will take a look. Hope you find a solution. Good luck :). Charlie
Thank you, Charlie =)
Hi Dima. Did you find a solution to this?
I just tried adding a clean umbraco 6.0.3 site and get the same error. So no uCommerce related issues here.
However it seems that it has some ambigous reference without really having it anyways. Very strange indeed.
Try removing your references to Umbraco and adding them again. I added a test project and added the references. It worked fine in that project.
Hi Morten. Where should I delete references from? I'm adding new test.cshtml to \macroScripts , it's content is
@current.ToString()
And it is already getting same exception. Razorstore project references are just for convenience when it comes to .cshtml.
It's totally the same on empty 6.1.0-beta Umbraco with just starter kit installed. Clearly not an issue with uCommerce.
Can you please elaborate on how you was able to _use_ var current = Node.GetCurrent(); ? (intellisense always used to say it's fine; runtime is different story)
Dima,
I meant a Testproject as in MSTest :)
The nuget package might do some strange stuff witht the references that it shouldn't do. However it is a wild guess.
Remove the reference to Umbraco in your web project and add it again. After doing so i got it working. Dunno what conflicted though.
Hm, I'm not using Visual Studio, or nuget for Umbraco. I just download it from codeplex, and throw it to webmatrix or IIS. And it doesn't have any "references". It just uses whatever it can find in /bin afaik. (maybe have something to do with web.config as well)
So you are saying that in bare console/text VS solution umbraco.NodeFactory library is working as expected. Good to hear.
But what is happening in Umbraco Macro? :)
Here is what happening: even though I do not write it, looks like Macro is automatically inherited from umbraco.MacroEngines.DynamicNodeContext (or from some other class, that's a child to BaseContext<>). This is a guess, but it sounds pretty much right.
This class have property named Node:
VoilĂ !
is working on a reply...