none
System.NullReferenceException: Object reference not set to an instance of an object. RRS feed

  • Question

  • @@RyanHill-MSFT

    Please could you or anyone assist. I keep getting this exception error:

    So I added a feature to upload files from our web app to a blob and I have already added the connection String details for the storage account to the app.config. But I keep getting this throw exception:

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error: 
    Line 28: 
    Line 29:                 {
    Line 30:                     string connstring = ConfigurationManager.ConnectionStrings["AzureStorageAccount"].ConnectionString;
    Line 31:                     string localFolder = ConfigurationManager.AppSettings["sourceFolder"];
    Line 32: 

    Source File: C:\Users\Tom\Source\Repos\Code\InspectorPlus.Web\App\Manage\UploadExternalFile\Default.aspx.cs    Line: 30 

    Stack Trace: 
    [NullReferenceException: Object reference not set to an instance of an object.]
       InspectorPlus.Web.App.Manage.UploadExternalFile.Default.Page_Load(Object sender, EventArgs e) in C:\Users\Tom\Source\Repos\Code\InspectorPlus.Web\App\Manage\UploadExternalFile\Default.aspx.cs:30
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +52
       System.Web.UI.Control.OnLoad(EventArgs e) +97
       System.Web.UI.Control.LoadRecursive() +61
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693


    AbaDougan

    Thursday, August 22, 2019 8:04 PM

Answers

  • The configSections you pointed out gets added when you add EntityFramework to your project. That's fine to leave alone. You should put your connectionStrings in the web.config. Just copy/paste the entire <connectionStrings>...</connectionStrings> from your app.config and redeploy.

    Feel free to reach back out if you continue to run into issues.


    Thanks in advance, Ryan

    Friday, August 23, 2019 12:51 PM
    Moderator
  • @Ryan, please I did that but I had to add the connection string for the storage account to the connection string already in the web.config and same for the app.settings but i was still getting the error..

    Also, from my research, I learnt I can use this below if i am having the parse issues.

    StorageCredentials credentials = new StorageCredentials("accountname", "key");
      CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);

    and I can now see the blobs in the blob container.

    Thanks for your support and help as always. 


    AbaDougan

    • Marked as answer by Aba Dougan Tuesday, August 27, 2019 12:19 AM
    Friday, August 23, 2019 6:36 PM

All replies

  • Aba,

    What is

    <connectionStrings>
       <add name="AzureStorageAccount" connectionString="..." />
    </connectionStrings>

    set to in your app.config? Are you including your app.config as a configSection in your web.config?



    Thanks in advance, Ryan


    Thursday, August 22, 2019 8:57 PM
    Moderator
  • Yes, I have connectionStrings in the app.config and not the web.config

    AbaDougan

    Thursday, August 22, 2019 9:04 PM
  • Do I need to add to the web.config?

    AbaDougan

    Thursday, August 22, 2019 9:07 PM
  • So the sql db connstring is also set up in the app.config but also in the web.config...

    in the app.config, the below is in the configSections....but looks like i have put the connectionString in the web.config

    <configSections>

     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=*****"

    requirePermission="false" />

      <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

    </configSections>


    AbaDougan

    Thursday, August 22, 2019 9:48 PM
  • The configSections you pointed out gets added when you add EntityFramework to your project. That's fine to leave alone. You should put your connectionStrings in the web.config. Just copy/paste the entire <connectionStrings>...</connectionStrings> from your app.config and redeploy.

    Feel free to reach back out if you continue to run into issues.


    Thanks in advance, Ryan

    Friday, August 23, 2019 12:51 PM
    Moderator
  • ok, I will do that, and revert ..thanks

    AbaDougan

    Friday, August 23, 2019 2:59 PM
  • @Ryan, please I did that but I had to add the connection string for the storage account to the connection string already in the web.config and same for the app.settings but i was still getting the error..

    Also, from my research, I learnt I can use this below if i am having the parse issues.

    StorageCredentials credentials = new StorageCredentials("accountname", "key");
      CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);

    and I can now see the blobs in the blob container.

    Thanks for your support and help as always. 


    AbaDougan

    • Marked as answer by Aba Dougan Tuesday, August 27, 2019 12:19 AM
    Friday, August 23, 2019 6:36 PM
  • Glade we were able to get it sorted out.

    Thanks in advance, Ryan

    Monday, August 26, 2019 1:05 PM
    Moderator