Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Null exception while using Dnn UserInfo class in windows console applicationNull exception while using Dnn UserInfo class in windows console application
Previous
 
Next
New Post
12/6/2014 12:15 PM
 

I'm facing null exception error while using below code in windows console application.

DotNetNuke.Entities.Users.UserInfo loUserInfo = new DotNetNuke.Entities.Users.UserInfo();
DotNetNuke.Entities.Users.UserController loController = new DotNetNuke.Entities.Users.UserController();
loUserInfo = loController.GetUser(0, 1);  => Error Line

I've already registered "DotNetNuke.dll" as a reference in application but still facing Null Exception on 3rd line.

Any help would be appreciated.


- Keval
 
New Post
12/6/2014 9:18 PM
 
This is not something that is a by design usage for DotNetNuke.dll. There are many parts of the dnn core that require access to a valid HttpContext and beyond that access to specific information that exists in the web.config of that running website context.

The dataprovider needs for example - access to SiteSqlServer connection settings so that it knows what database to look at. There are also an number of global objects that get created inside the context that need to exist before anything would run.

As a result - the correct way to access dnn from a console application is to create a webservice that runs inside the dnn hosting you want to access - and make calls to this service from you console application. That way the webservice handles all the httpcontext setup and knows where to look for its data etc.

Westa
 
New Post
12/7/2014 12:00 AM
 

Thanks Wes,

 Is it make sense if I add all those DNN global objects as well as DataProvider settings in app.config file? I've already set connection string like below in app.config file OR there is no way to do like that and I have to create web-service to use Dnn User Info?

 

<connectionStrings>
    <add name="SiteSqlServer" connectionString="Data Source=KEVAL;Initial Catalog=DNN711;User ID=sa;Password=sa123" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="SiteSqlServer" value="Data Source=KEVAL;Initial Catalog=DNN711;User ID=sa;Password=sa123" />
  </appSettings>


- Keval
 
New Post
12/7/2014 5:27 PM
 

There are just too many things that DNN needs to do to get itself setup inside the httpcontext for that sort of thing to be practical as far as I am concerned.   You could spend the next month trying to work out how to force dnn to work outside of a httpcontext (and still not succeed) - or you could make a webservice module in about 10 minutes.

http://www.dnnsoftware.com/wiki/page/services-framework-webapi

Westa

 
New Post
12/7/2014 11:52 PM
 
Thanks Wes,

Then web-service module is better way to go with.

- Keval
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Null exception while using Dnn UserInfo class in windows console applicationNull exception while using Dnn UserInfo class in windows console application


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out