Getting null reference exception on every api call
I'm trying to use the Umbraco API classes to do some stuff. The stuff itself doesn't matter because no matter what class or method I try to use I get a null exception on the object. I DO have the databases installed and running correctly. The site renders everything fine - I just can't access it from code. I've tried using alias calls (e.g. GetByAlias(name)) as well as looking up the IDs in the database itself and hardcoding them. I DO have the dlls added to my reference folder and I DO have using statements. Here are some of the commands that have failed:
Sorry if those are hard to read. I can paste in the text if necessary. I had just already taken screen shots so I could ask a friend about it.
I suspect this might be related to my connection string. It seems like it's just not getting the data. I changed my connection string at one point, incorrectly I think. And I can't remember what the initial string was. I tried to change it back - I think I am close, but maybe there is something wrong here:
Sorry to reply to my own post. I tried to edit it but got an XSLT parser error. Here's the edit:
EDIT: After working at it a while longer, the problem is not solved, but I have this to add: I no longer think the problem is the connection string. I actually created a second connection string using WebMatrix to generate it and that one doesn't work either. I guess that's doesn't DEFINITIVELY mean it's not the connection string, but it seems less likely. I also added the uCommerce package and I CAN programmatically access elements of that package without errors. Also, if I set a breakpoint and step through the code to look for the previously mentioned error, I've tried "Step Into" to see if I could figure out whether it was even getting to the database, but all I get is a "No Source Available" page. Which seems weird. I thought I read elsewhere that it was possible to step into the Umbraco source code. So maybe the source code is . . . I don't know . . . missing? Or misplaced.
The solution to this is that you cannot test Umbraco C# usercontrols in IIS. I thought I would be clever and test them using Visual Studio in conjunction with IIS, but most of the classes/methods in the Umbraco core have a "user" column (which defaults to -1 for the Back Office I believe). This field is null when you try to use VS and IIS - hence the null reference errors. The moral of the story is ALWAYS TEST YOUR USERCONTROLS IN UMBRACO ITSELF.
Getting null reference exception on every api call
I'm trying to use the Umbraco API classes to do some stuff. The stuff itself doesn't matter because no matter what class or method I try to use I get a null exception on the object. I DO have the databases installed and running correctly. The site renders everything fine - I just can't access it from code. I've tried using alias calls (e.g. GetByAlias(name)) as well as looking up the IDs in the database itself and hardcoding them. I DO have the dlls added to my reference folder and I DO have using statements. Here are some of the commands that have failed:
Node n = new Node(1176);
DocumentType dt = DocumentType.GetByAlias("Textpage");
umbraco.cms.businesslogic.Content[] docs = Document.getConentOfContentType(dt);
Here's the exception I get:
And the stack trace:
Sorry if those are hard to read. I can paste in the text if necessary. I had just already taken screen shots so I could ask a friend about it.
I suspect this might be related to my connection string. It seems like it's just not getting the data. I changed my connection string at one point, incorrectly I think. And I can't remember what the initial string was. I tried to change it back - I think I am close, but maybe there is something wrong here:
<add name="LocalSqlServer" connectionString="Data Source=USER-PC\SQLSERVER2012;Initial Catalog=WSC; Integrated Security=True" providerName="System.Data.SqlClient"/>
I am using Umbraco v 4.7.1.1, Microsoft .NET Framework Version:4.0.30319, and ASP.NET Version:4.0.30319.272.
Thanks in advance.
Sorry to reply to my own post. I tried to edit it but got an XSLT parser error. Here's the edit:
EDIT: After working at it a while longer, the problem is not solved, but I have this to add: I no longer think the problem is the connection string. I actually created a second connection string using WebMatrix to generate it and that one doesn't work either. I guess that's doesn't DEFINITIVELY mean it's not the connection string, but it seems less likely. I also added the uCommerce package and I CAN programmatically access elements of that package without errors. Also, if I set a breakpoint and step through the code to look for the previously mentioned error, I've tried "Step Into" to see if I could figure out whether it was even getting to the database, but all I get is a "No Source Available" page. Which seems weird. I thought I read elsewhere that it was possible to step into the Umbraco source code. So maybe the source code is . . . I don't know . . . missing? Or misplaced.
The solution to this is that you cannot test Umbraco C# usercontrols in IIS. I thought I would be clever and test them using Visual Studio in conjunction with IIS, but most of the classes/methods in the Umbraco core have a "user" column (which defaults to -1 for the Back Office I believe). This field is null when you try to use VS and IIS - hence the null reference errors. The moral of the story is ALWAYS TEST YOUR USERCONTROLS IN UMBRACO ITSELF.
is working on a reply...