I get this error when i have this in my codebehind: if(Page.User.Identity.IsAuthenticated)
System.NullReferenceException: Object reference not set to an instance of an object.
This error show when i use context.RewritePath method
http://localhost/page.apsx?id=22 --> http://localhost/hello-world/
Page.User.Identity.IsAuthenticated return True when i go to page.aspx?id=22 but i get
System.NullReferenceException: Object reference not set to an instance of an object.
error when i go to /hello-world/ url.
If the url.Contains("List") then rewrite the url like this:
context.RewritePath(Utility.WebRoot + "List/Add.aspx", false);
My rewriter is not more complicate then that.
Related
builder.Services.AddDbContext<AppDbContext>(x =>
{
x.UseSqlServer(builder.Configuration.GetConnectionString("SqlConnection"), option =>
{
option.MigrationsAssembly(Assembly.GetAssembly(typeof(AppDbContext)).GetName().Name);
});
});
System.InvalidOperationException: 'Cannot modify ServiceCollection after application is built.'
When I run the program I get the above error.
However, when trying to migrate, I get the following error
Unable to create an object of type 'AppDbContext'.
It looks like your adding this after builder.Build() has been called, difficult to see without the full code.
Can you try moving it before?
I have an asp.net WebAPI app. I'm returning files to the client in the Request.CreateResponse(,) second parameter as type Dictionary<string, List<System.Net.Http.StreamContent>>, where List<System.Net.Http.StreamContent>> contains all the files.
I'm deserializing the files at the client using the following:
var someContent = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<System.Net.Http.StreamContent>>>(result.Content.ReadAsStringAsync().Result);
This code throws the exception:
An unhandled exception of type
'Newtonsoft.Json.JsonSerializationException' occurred in
Newstonsoft.Json.dll.
Additional information: Unable to find a construction to use for type
System.Net.Http.StreamContent. A class should either have default
constructor, one constructor with arguments or a constructor marked
with the JsonConstructor attribute. Path 'myFiles[0].Headers'
Is there a different way to return actual files?
I'm attempting to pull out the Created UTC value from my Orchard project but I keep getting "object is null"
Here is my code
IUser loggedOnUser = _orchardServices.WorkContext.CurrentUser;
var userCreatedDate = loggedOnUser.As<CommonPart>().CreatedUtc;
When it hits the second line it throws the exception of "Object reference not set to an instance of an object".
Looking at this link my code should work fine.
User content item contains only a UserPart. If you need to access created/modified dates, you need to attach a CommonPart to it via data migrations, like this:
public int Create() {
ContentDefinitionManager.AlterTypeDefinition("User", cfg => cfg.WithPart("CommonPart));
return 1;
}
Just keep in mind that it won't affect existing users automatically - you would have to go through them one by one and hit "Save" for the part to be created.
I am receiving "Object reference not set to an instance of an object." when I am trying to add access token from fb to the httpcurrent.session object.
I have the value in the var accessToken and when I am trying to put it in the session I am getting the error.
Please refer to the image:
You need to enable session state in an HttpHandler, so you have to implement
System.Web.SessionState.IRequiresSessionState
Change to the following:
public class FacebookLogin : IHttpHandler, System.Web.SessionState.IRequiresSessionState
I'm using DotNetNuke 5.3. I add one menu item in ModuleActionCollection. Then I add this page to Module definition also. But I got this error:
Error: is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException:
Object reference not set to an
instance of an object. --->
System.NullReferenceException: Object
reference not set to an instance of an
object. at
DotNetNuke.UI.Modules.ModuleHost.LoadModuleControl()
--- End of inner exception stack trace
Are you using the ModuleActions property from the IActionable interface? Can you attach a debugger to that property and see if the NullReferenceException is happening in there? If you remove the IActionable interface from the module, does that get rid of the error?
Can you provide your implementation of ModuleActions?