NullReferenceException was unhandled

I am Building a Webbrowser in C#: this is the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Web_Browser
    public partial class Form1 : Form
        public Form1()
            InitializeComponent();
        private void goButton_Click(object sender, EventArgs e)
            webBrowser1.Navigate(new Uri(comboBox1.SelectedItem.ToString()));
        private void homeToolStripMenuItem_Click(object sender, EventArgs e)
            webBrowser1.GoHome();
        private void goBackToolStripMenuItem_Click(object sender, EventArgs e)
            webBrowser1.GoForward();
        private void goForwardToolStripMenuItem_Click(object sender, EventArgs e)
            webBrowser1.GoBack();
        private void Form1_Load(object sender, EventArgs e)
            comboBox1.SelectedText = "0";
            webBrowser1.GoHome();
the problem is: when I run it I get this error
"NullReferenceException was unhandeled"
at the bold line
can someone explane to me what I need to do??

Hi programming,
I have reproduced your code, and I was wondering what operation you made. If you debug your project and click the “goButton” after the form_load, it would appear the error message. It was becase your call the “comboBox1.SelectedItem” and “comboBox1.SelectedItem”
was never set. I think you could modify your Form1_Load like below:
private void Form0109_Load(object sender, EventArgs e)
//comboBox1.SelectedText = "0";
comboBox1.SelectedItem = comboBox1.Items[0];
webBrowser1.GoHome();
It would be helpful if you could share us how you get the error message.
Best Regards,
Edward
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.

Similar Messages

  • Crystal Report 11 error "AccessViolationException was unhandled" on windows

    We have migrated VB code to VS 2010. We are using Crystal Report 11 with Visual Studio 2010, Crystal report is working fine with other Windows OS but not working in Windows 7 OS it throws an error "AccessViolationException was unhandled". We are using Crystal Report viewer, the error stops at the viewer control and gives the above error. Please let me know what is the solution for this
    Note: All admin rights has been given to system

    Only version of CR runtime supported in VS 2010 is Cr for VS 2010:
    http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0_1.exe
    Thank you
    Don

  • ExternalException was unhandled : A generic error occurred in GDI+.

    I am try to save this bitmap as jpg file for every 5 sec. It works fine at another application, before I move this method to another app. The error message shows ExternalException was unhandled : A generic error occurred in GDI+. I do not know if
    it is write permission issure or anything else. Since I use same computer and try to save at same file path, the error message keep going. I think I need help.
    The error code:
    public void captureScreen()
    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    Debug.WriteLine("width:{0}, height:{1}", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    gfxScreenshot = Graphics.FromImage(bmpScreenshot);
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
    //Save the screenshot to the specified path that the user has chosen
    i++;
    string i1 = Convert.ToString(i);
    string name = "good" + i1 + ".jpg";
    ImageCodecInfo jpg = GetEncoder(ImageFormat.Jpeg);
    System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
    EncoderParameters myEncoderParameters = new EncoderParameters(1);
    EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder,
    50L);
    myEncoderParameters.Param[0] = myEncoderParameter;
    bmpScreenshot.Save(name, jpg,
    myEncoderParameters);
    Bitmap bitmap = new Bitmap(name);
    System.Drawing.Image image = (System.Drawing.Image)bitmap;
    The error shows here:
    bmpScreenshot.Save(name, jpg,
    myEncoderParameters);
    And Only alow me save one jpg, then pop up error

    Hi
    Since I can't reproduce your issue with some
    undefined code.
    Just take a look at from
    Graphics.FromImage Method
      in MSDN  document.
    You should always call the Dispose method to release the
    Graphics and related resources created by the
    FromImage method.  Please try and test it again.
    If still can't resolve, please post the complete code.  Thanks.
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Why do I get a "NullReferenceException was not handled by user code" error in one situation but not in the other?

    We are using Sharepoint 2010 and Infopath 2010.  In my form, I have a Managed Metadata field that I need to test for a Null value.  I found, with the help of this forum's participatns, that a [field]_Changed event for one MMD field runs multiple
    time because of the underlying XML elements (Terms, TermInfo, TermName, TermId).  So I'm trying to figure out how to test the XML to see when the TermName has a value.  By doing this, I hope to limit when the additional code in my form runs, i.e.
    I'll only trigger it when TermName is not null. 
    Just to test for null/empty (before doing anything that calls the addtional code) when I run this code, it completes correctly but always shows a message box:
    Dim strTest As String = Me.CreateNavigator.SelectSingleNode("/pr:properties/p:properties/documentManagement/ns2:h2b59c4ae4144c01973b1d8571d217ad", Me.NamespaceManager).InnerXml
                If String.IsNullOrEmpty(strTest) Then
                Else
                    MessageBox.Show("This is the value of the States InnerXML   " & strTest)
                End If
    But when I run this code, I get a "NullReferenceException was not handled by user code.  Object reference not set to an instance of an object" at the "Dim strTest..." line:
       Dim strTest As String = Me.CreateNavigator.SelectSingleNode("/pr:properties/p:properties/documentManagement/ns2:h2b59c4ae4144c01973b1d8571d217ad/pc:Terms/pc:TermInfo/pc:TermName", Me.NamespaceManager).InnerXml
                If String.IsNullOrEmpty(strTest) Then
                Else
                    MessageBox.Show("This is the value of the States InnerXML   " & strTest)
                End If
    Can any one explain why drilling down like this gives me this error?  And can you tell me how to get around it so I can limit how many times the code in my Infopath form needs to run?
    Thanks in advance.  Carol.

    Never mind, I think I've got it figured out.  When I do it this way, I get to the If Not...Nothing at the correct time. Thanks for sending me down the correct path, Scott. Carol.:
    Dim
    firstStr As
    String =
    String.Empty         
    Dim xNav
    As XPathNavigator = MainDataSource.CreateNavigator()
    Dim xFirst
    As XPathNavigator = xNav.SelectSingleNode("/pr:properties/p:properties/documentManagement/ns2:h2b59c4ae4144c01973b1d8571d217ad/pc:Terms/pc:TermInfo/pc:TermName",
    Me.NamespaceManager)
    If
    Not xFirst
    Is
    Nothing
    Then               
    Dim strxFirst
    As
    String = xFirst.InnerXml
                    MessageBox.Show(
    "Value of InnerXML   " & strxFirst)
    Else
                    MessageBox.Show(
    "Empty or Null")           
    End
    If

  • InvalidCastException was unhandled

    Hi,
    working with some in-house developed software, and after installing, and then uninstalling, a patch for VS2010, I suddenly get an "InvalidCastException was unhandled"
    The software is built on CodedUI, and the error appears when running the line 
    bw = BrowserWindow.Launch(data);
    The broswerwindow is opened, and the error is thrown before the next line is interpreted. 
    The error text reads:
    Unable to cast COM object of type 'Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IECommunicatorClass' to interface type 'Microsoft.VisualStudio.TestTools.UITest.Extension.IE.Communication.Interop.IIECommunicator'. This operation
    failed because the QueryInterface call on the COM component for the interface with IID '{95D738E9-E1F4-45EB-9DFF-E39671AF0CB7}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
    Anyone have an idea?

    Hi HakonRamanujan,
    >>Get the same message when trying to record steps with CodedUI, when trying to access some controls on web pages.
    Do you mean that you still get this issue if you record a simple coded UI test? I mean that whether all coded UI tests have the same issue, maybe you could install the VS2010 sp1. Test it again.
    Please also make sure that the Coded UI test supports these controls.
    https://msdn.microsoft.com/en-us/library/dd380742(v=vs.100).aspx
    In addition, whether you recorded the test in the latest version like VS2013 before? Maybe you could test it in VS2013 version.
    Best Regards,
    Jack 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • TypeInitializationException was unhandled

    Hello,
    I was able to successfully compile this program, but received this error message when trying to debug. 
    Can anyone provide any help or advice on how to best go about resolving this?
    Kenny

    Hi Kenny,
    It showed the exception window since we enabled the exception thrown under Debug->Exception window.
    But the real issue would be related to your project code.
    Reference:
    http://stackoverflow.com/questions/4110168/c-sharp-error-when-i-try-to-compile 
    http://stackoverflow.com/questions/5179156/system-typeinitializationexception-was-unhandled
    Like above two cases, you would look at the detailed inner exception to find out where the real problem is.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Need help with Connect 4 game, IndexOutOfRangeException was unhandled

    Hi! I've been struggling with this for a while now, the issue is that as soon i move a game piece to the field i get this errorats "IndexOutOfRangeException was unhandled" and i don't know why since my intention with the code was to use for loops
    look through the 2D array thats based on two constants: BOARDSIZEx = 9 and BOARDSIZEy = 6. Instead of traditional 7*6 connect 4 grid i made it 9 squares wide due to having pieces on the side to drag and drop.
    Here's the code for my checkwin:
    public bool checkWin(Piece[,] pieceArray, bool movebool)
    bool found = false;
    //Horizontal
    for (int i = 0; i < BOARDSIZEx - 3; i++)
    for (int j = 0; j < BOARDSIZEy; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i, j + 1])
    && (pieceArray[i, j] == pieceArray[i, j + 2])
    && (pieceArray[i, j] == pieceArray[i, j + 3]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    //Vertikal
    for (int i = 0; i < BOARDSIZEx; i++)
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i + 1, j]) && (pieceArray[i, j] == pieceArray[i + 2, j])
    && (pieceArray[i, j] == pieceArray[i + 3, j]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    //Diagonal, Lower left to upper right
    for (int i = 0; i < BOARDSIZEx - 3; i++)
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i + 1, j +1])
    && (pieceArray[i, j] == pieceArray[i + 2, j + 2])
    && (pieceArray[i, j] == pieceArray[i + 3, j + 3]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    //Diagonal, upper left to lower right
    for (int i = 0; i >= BOARDSIZEx; i--)
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i - 1, j + 1])
    && (pieceArray[i, j] == pieceArray[i - 2, j + 2])
    && (pieceArray[i, j] == pieceArray[i - 3, j +3]))
    if (pieceArray[i, j].IsStarter != movebool)
    found = true;
    goto Done; //interesting way of getting out of nested for loop
    //for more on goto: http://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop
    Done:
    return !found;
    It's at the vertical check that the error occurs and also my checkwin doesnt seem to respond to the call in the game.cs code.
    //check for win
    bool moveBool = true; //returns yes or no depending on whether both players have moved their pieces
    if (move % 2 == 0) moveBool = false;
    bool win = rules.checkWin(pieceArray, moveBool);
    //The game is won!
    if (win)
    string winningPlayerName = player1.Name; //creating a new player instance, just for shortening the code below
    if (moveBool == false) winningPlayerName = player2.Name; //if it was player 2 who won, the name changes
    message = winningPlayerName + " has won the game!\n\n"; //The name of the player
    Board.PrintMove(message); //Print the message
    if (moveBool == true) player1.Score += 1; else player2.Score += 1; //update score for the players
    //The player's labels get their update texts (score)
    Board.UpdateLabels(player1, player2);
    //Here, depending on what one wants to do, the board is reset etc.
    else
    move++; //draw is updated
    And here's a picture on how it looks like at the moment.
    Thanks in Advance!
    Student at the University of Borås, Sweden

    for (int i = 0; i < BOARDSIZEx; i++) // If BOARDSizex is the number of elements in the first dimension...
    for (int j = 0; j < BOARDSIZEy - 3; j++)
    if ((pieceArray[i, j] != null)
    && (pieceArray[i, j] == pieceArray[i + 1, j]) && (pieceArray[i, j] == pieceArray[i + 2, j])
    && (pieceArray[i, j] == pieceArray[i + 3, j])) // Then [i + anything, j] will be out of range.
    You probably meant to add the one, two, or three to the j rather than the i.

  • DirectoryNotFoundException was unhandled by user code

    I have taken over a pre-existing application from the previous developer. I was able to successfully compile the application, but when I attempt to debug the application I receive the error message below:
    Does anyone have an idea what this is referring to and how to resolve it?
    Thanks,
    Kenny

    Hi Kenny,
    Which kind of project did you debug?
    >>An unhandled exception of type  'System.IO.DirectoryNotFoundException'  occurred in mscorlib.dll
    Additional information: Could not find  a part of the path...
    Generally the error message means that it would be related to the resources management.
    Reference:
    http://stackoverflow.com/questions/4216396/system-io-directorynotfoundexception-after-deleting-an-empty-folder-and-recreati
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/6eacf70d-f229-4cc1-8868-fba98008455a/c-systemiodirectorynotfoundexception-after-deleting-an-empty-folder-and-recreating-it?forum=csharpgeneral
    Maybe you could click "View Detail" to get more information in your side, but I doubt that it would be not the VS IDE issue.
    Best Regards,
    Jack 
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • InvalidOperationException was unhandled by user code

    Hi,
    I'm trying to validate the date format of the command using these codes. But I'm with the captioned error? Any advice for it?
    protected void gv_upd_rec(object sender, GridViewUpdateEventArgs e)
    int rIndex = e.RowIndex;
    OracleConnection conn = new OracleConnection("Data Source=XE;User ID=my_schema;Password=wsabc;");
    OracleDataReader reader;
    string start_date = gv1.Rows[rIndex].Cells[1].Text;
    string end_date = gv1.Rows[rIndex].Cells[2].Text;
    try
    OracleCommand cmd = new OracleCommand("select to_date(:start_date,'dd/Mon/rr'),to_date(:end_date,'dd/Mon/rr') from dual", conn);
    cmd.Parameters.AddWithValue("start_date", OracleType.VarChar).Value = start_date;
    cmd.Parameters.AddWithValue("end_date", OracleType.VarChar).Value = end_date;
    reader = cmd.ExecuteReader();
    catch (OracleException ex)
    ClientScript.RegisterClientScriptBlock(Page.GetType(), "alert", "alert('Invalid date format is entered: " + ex.Message + ".');", true);
    return;
    finally
    }

    Hi,
    You're using Microsoft's data provider, not Oracle's, so a Microsoft forum may be a better place to post your problem.
    However, I did try this, and it worked fine for me:
    using (OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl"))
                con.Open();
                using (OracleCommand cmd = new OracleCommand("", con))
                    cmd.CommandText = "select to_date(:start_date,'dd/Mon/rr'),to_date(:end_date,'dd/Mon/rr') from dual";
                    cmd.Parameters.AddWithValue("start_date", OracleType.VarChar).Value = "01/JAN/02";
                    cmd.Parameters.AddWithValue("end_date", OracleType.VarChar).Value = "01/JAN/08";
                    OracleDataReader reader = cmd.ExecuteReader();
                    Console.WriteLine(cmd.ExecuteScalar().ToString());
            }OUTPUT
    ======
    1/1/2002 12:00:00 AM
    I'm not sure why you're calling both ExecuteReader() and ExecuteScalar(), I assume that's just for debugging purposes?
    Greg

  • IndexOutOfRangeException was unhandled

    Good Day,
    Hi to all Expert, i have some problem with my code, but basically its just a reading a data from the database but bug still pop-up, see the image
    The "no_days" field is exist, when i'm using insert and update statement is still working but when i retrieve it the bug stay stood, please help me,
    Thanks in advance,

    Hi Mr. Monkeyboy,
    Sorry for the unspecific sources, here's the code,
    dbsql("select * from personalinfo where refid=1")
    dr = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
    While dr.Read
    cmbRefStatus.Text = dr("refstatus").ToString
    txtRefDateReg.Text = dr("datereg").ToString
    txtRefAttn.Text = dr("attn").ToString
    txtRefPurpose.Text = dr("purpose").ToString
    txtClassNo.Text = Int(dr("class_no")) 'bug upon here "no_days" but the data values is 5
    numNoOfDays.Value = dr("no_days")
    txtEndDate.Text = DateTime.Parse(dr("enddate").ToString).Date
    txtRefLname.Text = dr("lastname").ToString
    txtRefFname.Text = dr("firstname").ToString
    txtRefMname.Text = dr("middlename").ToString
    dtpRefbirthdate.Value = dr("birthdate").ToString
    cmbRefSex.Text = dr("sex").ToString
    txtRefCountry.Text = dr("country")
    txtRefCity.Text = dr("city").ToString
    txtRefAddr1.Text = dr("addr1").ToString
    txtRefAddr2.Text = dr("addr2").ToString
    txtRefPhone.Text = dr("phone").ToString
    txtRefTel.Text = dr("telphone").ToString
    txtRefEmail.Text = dr("email").ToString
    txtRefCompany.Text = dr("company").ToString
    txtRefCoAddr.Text = dr("coaddr").ToString
    txtRefCoPhone.Text = dr("cophone").ToString
    txtRefCoTel.Text = dr("cotelphone").ToString
    txtRefCoEmail.Text = dr("coemail").ToString
    End While
    I'm using sql server,
    numNoOfDays.Value = dr("no_days")
    'Data from no_days=5
    'the numNoOfDays.Value range is from 0 to 100

  • ArgumentException was unhandled by user code

    Hi,
    I am a new user of ODP.net and Oracle. I have a stored procedure whose in parameter is UDT. It is a table of type Object. I need to know what would be its equivalent in .Net?
    E.g.
    create or replace
    TYPE TEMP_OBJ AS OBJECT (
    a_id number,
    Name varchar2(256),
    flag char(1),
    user varchar2(256) )
    create or replace
    type ACTUALONE is table of TEMP_OBJ
    procedure submit_proc
    (i_actual in actualone,
    o_status out number,
    o_err_message out varchar2);
    How do I map my oracle fields with the C#.Net. What do I do to execute the above stored procedure i.e. "submit_proc" from my .Net code? I want a code or explanation on how to ride on this beast.

    837779 wrote:
    Hi Alex,
    I do not intend to do this stuffs from UI. The link that you have sent me would have been of gr8 help if I had to do it by UI. I want to code my entire requirement and I cannot add the server in the .Net as I do have the tns entries in my .ora file and I am not even allowed to do that. So please if you can send in some code that can explain me the solution to my problem.You should at least read through the walkthrough Alex provided you even if it involves UI elements. It includes the information you are looking for in the "Generating Custom Classes for User-Defined Types" section.

  • Entityexception was unhandled by user code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using MvcDemo.Models;
    namespace MvcDemo.Controllers
        public class EmployeeController : Controller
            public ActionResult Details( int id )
                EmployeeContext employeeContext = new EmployeeContext();
                Employee employee =  employeeContext.Employees.Single(emp => emp.EmployeeId == id);    //when i debugg this project then this error line occurred at this line
                return View(employee);
     i try to retrive data from the table and by id column 
                               

    Well you need to find out what the error is and post it, because otherwise, only Harry Houdini can pull that rabbit out of the hat for you.
    Harry would put a try/catch around the code and catch the exception and pull the rabbit out by its ears.

  • StackOverflowException was unhandled when I set the datacontext of xaml to the partial class?

    <Page x:Class="GraphToTable.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:src="clr-namespace:GraphToTable"
    mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="1200" Width="auto" Height="auto"
    Title="Page1">
    <Page.DataContext>
    <src:Page1/>
    </Page.DataContext>
     Does this means that I cannot set the datacontext from xaml to same class that it's referring to? 

    Hi Boppy,
    It can be set to DeatContext at only design time using d:DataContext , and can be set at run time using RelativeSource.
    <Page x:Class="GraphToTable.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:src="clr-namespace:GraphToTable"
    mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="1200" Width="auto" Height="auto" Title="Page1"
    d:DataContext="{d:DesignInstance Type=src:Page1}"
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <Grid>
    <TextBlock Text="{Binding Path=ActualHeight}" />
    </Grid>
    </Page>
    個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)

  • ArgumentNullException was Unhandled

    heey you guys,
    I have this error and I dont know How I can Solve it,
     this.timer1 = new System.Windows.Forms.Timer(this.components); // its about this line of code
    Does anybody know the solution to this error??
    thkns

    Create the Timer after the call to InitializeComponent():
    public Form1()
    InitializeComponent();
    this.timer1 = new System.Windows.Forms.Timer(this.components);
    Or use the constructor overload that doesn't take any argument:
    this.timer1 = new System.Windows.Forms.Timer();
    Please remember to close your threads by marking helpful posts as answer and please start a new thread if you have a new question.

  • WPF Map Control Throws NullReferenceException

    This is a weird problem.  The exception only happens if I have a break point in my project that is hit before the project is fully loaded (before the window appears on the screen).  Not every break point causes the exception.  I have not been
    able to pinpoint what particular break points do and do not cause it.  I think it might be break points that are hit before some event happens on the UserControl that is hosting the map control but if that is the case I am not sure what event that might
    be.  If you remove the break point the application works fine.  Break points that are hit later in the application do not cause a problem.
    Here is a copy of the exception:
    System.NullReferenceException was unhandled
      HResult=-2147467261
      Message=Object reference not set to an instance of an object.
      Source=Microsoft.Maps.MapControl.WPF
      StackTrace:
           at Microsoft.Maps.MapControl.WPF.MapCore.AnimateViewUsingZoomAndPan(Double zoomLevel, Point centerNormalizedMercator)
           at Microsoft.Maps.MapControl.WPF.MapCore.SetViewInternal(Point centerNormalizedMercator, Double zoomLevel, Double heading)
           at Microsoft.Maps.MapControl.WPF.MapCore.SetView(LocationRect boundingRectangle)
           at GeoservicesControls.Views.GeofencingView.<>c__DisplayClass8.<ViewModelChangedCallback>b__0(LocationRect x) in d:\SoftwareDevelopment\AccessibleSolutions\GeoservicesControl\Source\GeoservicesControls\Views\GeofencingView.xaml.cs:line
    121
           at System.Reactive.AnonymousSafeObserver`1.OnNext(T value)
           at System.Reactive.Concurrency.ObserveOn`1.ObserveOnSink.OnNextPosted(Object value)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.DispatcherOperation.InvokeImpl()
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Windows.Threading.DispatcherOperation.Invoke()
           at System.Windows.Threading.Dispatcher.ProcessQueue()
           at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
           at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run()
           at GeoservicesControl.Shell.Wpf.App.Main() in d:\SoftwareDevelopment\AccessibleSolutions\GeoservicesControl\Source\GeoservicesControl.Shell.Wpf\obj\Debug\App.g.cs:line 50
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: 

    The error message indicates that the error was thrown from the GeofencingView.xaml.cs file around line 121. Can you provide the code that you have in that area and the values being used.
    http://rbrundritt.wordpress.com

Maybe you are looking for