Using an HTML Link - c#

I have a C# ASP.NET application that throws an "Object reference not set to an instance of an object" exception.
The line that throws the exception is
HtmlLink cssTemplate = new HtmlLink();
I am using the cssTemplate variable in my site to set the CSS sheet on my masterpage based on the logged in user.
Any ideas as to why I would get this error on instantiation of the cssTemplate object?
Update: The entire snippet from the exception is
Message: Object reference not set to an instance of an object.
Stack Trace: at LRMasterPage.Page_Load(Object sender, EventArgs e in
LRMasterPage.master.cs:line 49
Target Site: Void Page_Load(System.Object, System.EventArgs)
Data: System.Collections.ListDictionaryInternal
I am wondering now if it is the System.Collections.ListDictionaryInternal that might actually be the issue.

Related

Error while reading mail from pop3client

I am trying to read emails from pop3clent with following code:
Pop3Client pop = new Pop3Client();
pop.Connect(mailHost, portNum, false);
pop.Authenticate(userName, passWord,AuthenticationMethod.UsernameAndPassword);
And I am getting error while authenticating:
"Object reference not set to an instance of an object."
You might be getting the error elsewhere if you are sure all your objects in the code you posted does not contain null values.

Further explanation on a basic C# error for redirecting

Error Message: Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 17: else // Else they will be redirected and given the message below in the label
Line 18: {
Line 19: lblSession.Text = "On the previous page, you typed in " + Session["contentOfTextBox"].ToString();
Line 20: }
Line 21: }
Source File: c:\Users\Ryan\Desktop\asppub\MIS3200\Unit6\RingU6L1_2.aspx.cs Line: 19
You have to check if Session exists before using it. You are calling ToString on Session["contentOfTextBox"] which is probably null. Because either session does not exists or expired.
if( Session["contentOfTextBox"] != null)
lblSession.Text = "On the previous page, you typed in " + Session["contentOfTextBox"].ToString();

Does LibGit2Sharp support cloning a repository from the local file system?

I am trying to clone a git repository from the local file system:
using System;
using LibGit2Sharp;
class Program
{
static void Main()
{
var sourceUrl = #"file:///c:/work/libgit2sharp";
using (Repository.Clone(sourceUrl, "targetDir", bare: true))
{
Console.WriteLine("repository successfully cloned");
}
}
}
and I get an exception:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: An error was raised by libgit2. Category = Odb (Error).
Failed to find the memory window file to deregister
at LibGit2Sharp.Core.Ensure.Success(Int32 result, Boolean allowPositiveResult) in c:\work\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 85
at LibGit2Sharp.Core.Proxy.git_clone_bare(String url, String workdir, git_transfer_progress_callback transfer_cb) in c:\work\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 219
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, Boolean bare, Boolean checkout, TransferProgressHandler onTransferProgress, CheckoutProgressHandler onCheckoutProgress) in c:\work\libgit2sharp\LibGit2Sharp\Repository.cs:line 431
at Program.Main() in c:\work\ConsoleApplication1\Program.cs:line 10
I've also tried the following source url:
var sourceUrl = #"c:\work\libgit2sharp\.git\";
and got another exception:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: An error was raised by libgit2. Category = Config (Error).
Failed to parse config file: Unexpected end of file while parsing multine var (in c:/work/ConsoleApplication1/bin/Debug/targetDir/config:23, column 0)
at LibGit2Sharp.Core.Ensure.Success(Int32 result, Boolean allowPositiveResult) in c:\work\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 85
at LibGit2Sharp.Core.Proxy.git_clone_bare(String url, String workdir, git_transfer_progress_callback transfer_cb) in c:\work\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 219
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, Boolean bare, Boolean checkout, TransferProgressHandler onTransferProgress, CheckoutProgressHandler onCheckoutProgress) in c:\work\libgit2sharp\LibGit2Sharp\Repository.cs:line 431
at Program.Main() in c:\work\ConsoleApplication1\Program.cs:line 12
targetDir is never created.
If on the other hand I use HTTP transport, the Repository.Clone method works fine:
var sourceUrl = "https://github.com/libgit2/libgit2sharp";
So my question is if I am doing something wrong or if this is unsupported feature or a bug in the native git2.dll?
So my question is if I am doing something wrong or if this is unsupported feature or a bug in the native git2.dll?
A bit a both, actually.
The first exception is clearly a bug. This should not happen and will be troubleshot.
The second one requires a deeper analysis. Would you be so kind as to open a issue in the LibGit2Sharp project?
Good news are that a pull request from BenStraub was recently merged. This pull request implements the local fetch transport which should pretty solve the issue.
LibGit2Sharp will be updated in the following days with a new a new version of libgit2 binaries which should allow you perform a local clone/fetch. I'll update this answer as soon as it's been done.
Update
This test shows how do to a Clone and a Push over against a local repository.

Is there any way to go to all links in page in watin i have used the following code but no use

couple of days back i have used the same code to go to each and every page, today it doesn't work. Does anyone know an other approach than this:
var browser = new IE("http//www.xyz.com");
foreach (Link l in browser.Links)
{
Console.WriteLine(l.Url);
if (l.Url.IndexOf("javascript") == -1)
{
browser.GoTo(l.Url);
browser.WaitForComplete();
Thread.Sleep(200);
browser = IE.AttachTo<IE>(Find.ByUrl(browser.Url));
browser.Back();
}
}
error Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
A NullReferenceException means that you are trying to call a method or access a field/property of a null object. You need to step through this code and figure out what is null when it shouldn't be using the debugger.

Response.BinaryWrite gives error on Production

I'm using localReport to print PDF (SQL REPORTVIEWER). It works fine on localhost. When I move the application to Production (64 bits windows 2008) it gives me an error. (see below)
I put the renderedbytes in a Session in USERCONTROL and I do window.open('Program1.aspx')...
In page load of Program1.aspx I try to retrieve the Session variable and process....
I think this statement cause the error "Response.BinaryWrite (...) etc".
It works on my local pc (Vista 32bits)...
Can someone please what the errors says? and How can I solve this on production??????
thank you..
USERCONTROL1.ASCX
byte[] renderedBytes;
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
Session["report"] = Print.RenderReport(listEnt, Language);
PROGRAM2.ASPX
protected void Page_Load(object sender, EventArgs e)
{
string extension = "PDF";
Response.ContentType = "application/pdf";
// set the MIME type here
Response.AddHeader("content-disposition", "inline: filename=Test." + extension);
Response.BinaryWrite((byte[])Session["report"]);
Response.End();
}
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.HttpResponse.BinaryWrite(Byte[] buffer) +13
ConfederatieBouw.CustomModules.Controle_InhoudingsPlicht.WebForm1.Page_Load(Object sender, EventArgs e) +191
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsync
Are you running a web farm in production? If so, how are you storing session state? The default is InProc, which means the session will only exist on one server in the farm, and if the follow up request goes to another server, that would explain the issue. The fix this scenario, you will need to setup some sort of session state that can be shared across servers (such as a session state server or SQL Server session state).
Here is some info on the various session state providers:
http://msdn.microsoft.com/en-us/library/ms178586.aspx
Session["report"] is null. You're not setting it to renderBytes in the user control.
Also, it's a really bad idea to store this in a Session. Your binary data has to be serialized/encoded and then deserialized/unencoded whenever you set the Session[] value, which performs poorly. Create a property on the user control to accept the report object and write it to the output stream there, or just do it in the page itself. I'm not sure that it makes sense to put this in a user control instead of a regulat class, anyway.

Categories

Resources