Click here to Skip to main content
14,733,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting the below error for a release .exe of a windows form application i am building. The issue strangely only occurs when i try to run the .exe outside out of the release directory it was generated ?! It works fine when ran in visual studio or by running the .exe file in the release directory. After the below error i have included the suspect code. It appears trying to connect to the database seems to be a issue but i do not know why

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at WindowsFormsApplication4.DataAccess.DataAccess.get_ConnectionString()
at WindowsFormsApplication4.DataAccess.DataAccess.AuthenitcateCredentials(String username, String password)
at WindowsFormsApplication4.LoginRegister.Login_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
Assembly Version:
Win32 Version: 4.0.30319.296 (RTMGDR.030319-2900)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
Assembly Version:
Win32 Version:
CodeBase: file:///C:/Users/Admin/Documents/dt265/Project/website/WindowsFormsApplication4.exe
Assembly Version:
Win32 Version: 4.0.30319.278 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
Assembly Version:
Win32 Version: 4.0.30319.282 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
Assembly Version:
Win32 Version: 4.0.30319.296 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
Assembly Version:
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.Entity/v4.0_4.0.0.0__b77a5c561934e089/System.Data.Entity.dll
Assembly Version:
Win32 Version: 4.0.30319.233 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
Assembly Version:
Win32 Version: 4.0.30319.237 (RTMGDR.030319-2300)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
Assembly Version:
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
Assembly Version:
Win32 Version: 4.0.30319.233 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the section.
The application must also be compiled with debugging

For example:

< jitdebugging="true">

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

public class DataAccess
        public BusinessObjects.User CurrentUser = new BusinessObjects.User();

        private string ConnectionString
            get { return ConfigurationManager.ConnectionStrings["DatabaseEntities"].ToString(); }

        public BusinessObjects.User AuthenitcateCredentials(string username, string password)
            using(var dataContext = new DatabaseEntities(ConnectionString))
                var user = dataContext.Users.FirstOrDefault(u => u.Username.Equals(username) && u.Password.Equals(password));
                if (user == null) return null;
                CurrentUser = GetUser(user.UserId);
                return CurrentUser;

1 solution

Did you copy the AppConfig file to your Exe folder?

since you are using the Configuration manager you need to keep the AppConfig file generated when you build the application inside the executable folder.
Darith1974 23-Dec-12 16:05pm
No, i did not; but when i copied the config to the same folder as i relocated a copy of the .exe; it solved the error. I presumed generated a release version would include a application configuration. So do i need to have two files or is it possible to create one? Maybe using the publish service in visual studio?
Jibesh 28-Dec-12 16:08pm
when you build the application the app config file will create automatically by the visual studio compiler with the same of the Project. App config will be created for both the version but you need to keep the exe and config in the same folder to use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900