Error when building existing solution in Visual Studio - asp.net

Hy guys,
I got one existing project from my co-worker. I opened the folder in VS as web site. When I build it and try to run I get the following message-
Warning C:\Users......: ASP.NET runtime error: Object reference not set to an instance of an object.
Error - Object reference not set to an instance of an object.
I have a Visual Studio 2012, registered as student version, target framework is 2.0

Try to check your project reference to load well, not missing reference (you can check in folder "Reference"), or sometime this error because your object is not initialize [blank value], you can add images to give us detail information for your issue.

That is called a Null Reference, you (the code) try to use an object which is not created/initialised yet.
Its impossible to give you an answer which would fix your issue, you will have to debug the code yourself.
When the exception occurs, visual studio should ask you if you want to 'break' or 'continue'. Choose break and check where in the code the error is, then take it from there.
//Example:
AClassofSomeSort myObj2 = new AClassofSomeSort();
myObj2.DoSomething(); //Totally fine, cause the myObj2 have been initialised.
AClassofSomeSort myObj;
myObj.DoSomething(); //Oh noes, the 'myObj' is not created! Exception is thrown.

Related

Object reference not set to an instance of an object in BizTalk project

I have a solution that contains three BizTalk projects named BizTalk.Schemas, BizTalk.Pipelines and BizTalk.Archive.Component.
When I am Rebuilding the solution, It is throwing error of "Object reference not set to an instance of an object" in pipelines(.btp) under BizTalk.Pipelines project.
I have added all the reference in the respective project but still it is giving the same error.
Can anyone help me that what i am missing in pipelines(.btp)?
Looks like visual studio issue to me. try unloading and loading the project again. which Visual studio version are you using?

Activation error occured while trying to get instance of type AttributeValidatorFactory, key ""

I'm using Visual Studio 2010 and Enterprise Library Validation 5.0.505.0 in my class library. But I'm facing error like
Activation error occured while trying to get instance of type AttributeValidatorFactory, key ""
I face error on the following line.
Validation.ValidateFromAttributes(obj);
where obj is the custom object.
I don't how to solve this one. Please, help !!
Thanks in advance.
I just add the Microsoft EnterpriseLibrary reference to my Website. In my case the DLL Microsoft.Practices.EnterpriseLibrary.Validation resides in the following path
C:\Program Files (x86)\Microsoft Enterprise Library 5.0\Bin\Microsoft.Practices.EnterpriseLibrary.Validation.dll
To find out the path you should follow the step.
Right Click on the DLL > Click on Properties > Here there is property naming
Path
And a very small trick.
Right Click on the DLL > Click on Properties > Make Copy Local to True (By default the property is False)
Now, I Clean my solution and Build it and re-run the solution.
The application is running properly without any error. BINGO !!!!

"WebSecurity" does not exist in the current context error in _AppStart.cshtml

I am getting the following compilation error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'WebSecurity' does not exist in the current context
Source Error:
Line 1: #{
Line 2: if (!WebSecurity.Initialized)
Line 3: {
Line 4: WebSecurity.InitializeDatabaseConnection("AreaProject", "User", "UserId", "EmailAddress", autoCreateTables: true);
Source File: c:\Projects\area\trunk\dotNet\area.Web\area.Web\_AppStart.cshtml Line: 2
enter code here
My project is correctly referencing to "System.Web" and my other files that are using " System.Web.Security" are compiling fine.
The problem started when I added the references System.Web, System.Web.Pages and System.Web.Razor to my application. But I didn't make any change to WebMatrix.WebData or WebMatrix.Data.
The WebSecurity class that is being referenced here is apart of WebMatrix.WebData and not System.Web or System.Web.Security. You probably need to add a reference to WebMatrix.WebData.dll and things should at least get past the runtime compiler error.
You get the compiler error at runtime because views are normally compiled when the application starts up for the first time, instead of when the assemblies are complied.
I'm assuming you are trying to run the MVC4 application first time.
MVC4 adds boatload of assembilies for Internet Application template. It becomes PIA to remove them if you do not use it.
Basically, if you do not use WebMatrix or OAuth to authenticate, you can just comment out everything inside SimpleMembershipInitializer class.
private class SimpleMembershipInitializer
{
// Comment out everything
}
Just for testing, you can also comment out every line inside AccountController that throw exception.
Old thread, but just in case it helps someone down the road. I am not sure why it works this way, but sometimes installing packages like WebMatrix.WebData, WebMatrix.Data is not enough. When I look at the Reference section of my application after these assemblies were installed, WebMatrix.WebData, WebMatrix.Data were still not showing up there, although they were in the BIN folder of the application. I had to literally use Add Reference to make them. Only then, they shown up and everything started working.

ASPNETCOMPILERERROR - object reference not set to an instance of object

I am getting ASPNETCOMPILERERROR while publishing a web project.
This project is in .net 4.0 and we are publishing in VS2012.
Build is getting succeeded, but while publishing we are getting following error
ASPNETCOMPILERERROR - object reference not set to an instance of object.
Please let us know how to resolve the issue.
I am able to solve the issue.
One of the dll causing reference issue, but build is getting succeed.
Solved by following these steps
Checked in the temporary folder(C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files) where VS Creates dlls for each page( i have opted for individual assemblies while publishing)
Before creating dlls, it generates .Compiled files and then converts each file to a dll.
we found one of the page is not getting converted to dll, instead it created a file with .delete extension and halted.
Now we ran our application from VS and tried open the page which is not able getting converted to dll.
Now we got the issue as an exception.
Hope this will help some one else.

What is causing intermittent "Object reference not set to an instance of an object" at compile time in VS 2010?

I am sorry if this is not really a coding question (it depends on if its my code causing the problem I suppose).
I have seen this question: Tracking down intermittent 'Object reference not set to an instance of an object.' error on build
However, it has not been of much help (although if you read the comments, you will see that I thought it did help for a while there).
When I try publish my website, occasionally, I will get an error with no file or line reference:
Pre-compiling Web Site
Building directory '/App_Code/'.
Building directory '/'.: Publication (web): Object reference not set to an instance of an object.
Pre-compilation Complete
------ Skipped Publish: Project X:\, Configuration: Debug Any CPU ------
I know the usual causes of "Object reference not set to an instance of an object" but this seems a bit different, isn't it supposed to be a runtime error? Not a build error?
What is weird is that it happens, seemingly at random (about 25%-33% of the time). I can try to publish it and have it fail. Then try again straight after, without changing anything and it works fine.
I started getting this error after moving some of my functions (VB.net btw) to a new file in the App_Code folder so they can be accessed by all pages of the site.
If you need any more info, please let me know.
Thanks,
EDIT: After further investigation, it seems to only happen if I try to publish the website within a few seconds of saving changes to any file within it. What could cause this?
The same error occurred for me to, I deleted the dlls of the custom controls in the web site that are already in the bin, then i published the web site, and succeeded
IF you have any custom/usercontrols in your project, they are actually running at design time and can give object ref errors. This can occur during builds too. In that case, a property is being referenced that is NOTHING and throws the error.
I had a similar problem with a Windows Form project.
Wherever I try to move a custom control on the windows form, and then try to save the form, VS2010 comes back with "Object not set to an instance of an object".
I suspected the error was deep down in the layers of abstraction in my inherited code, but couldn't work out how deep to go, without reviewing every line of code.
My solution to this problem is this.
Open up another instance of Visual Studio 2010
Menu: Debug | Attach to Process..
Search for "devenv.exe xxx YourApplicationName..." and select it
Click "Attach"
Menu: Debug | Exceptions..
Tick all the boxes in the thrown column, then "OK"
Your second instance of VS2010 is not debugging your first instance, including all the custom controls.
Return to the first instance of VS2010, and repeat the actions that caused the error in the first place, the second instance of VS2010 will break at the line of code that has the error.
You may want to look at this link there is a bug in vs2012
https://connect.microsoft.com/VisualStudio/feedback/details/749901/error-when-i-click-publish-object-reference-not-set-to-an-instance-of-an-object

Resources