Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7779619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:41:05+00:00 2026-06-01T18:41:05+00:00

When i debug code with f10 IT WORKS with NO ERROR !.But on runtime

  • 0

When i debug code with f10 IT WORKS with NO ERROR !.But on runtime i got this error:
“An item with the same key has already been added”

Plz help

My Dictionary :

public static Dictionary<string, string> ImageFilePath
        = new Dictionary<string, string>();

Using in same Glob.cs my function :

public static Image ShowImageOnColumn(string Value,byte ImageHeigth,byte ImageWidth)
{

   .
   .
   .

    string FilePath = "",ImgId = "";


    Image img_ = new Image();

    Random rnd = new Random();

    ImgId = rnd.Next(100000000).ToString();
    img_.ImageUrl = "ShowImageInRuntime.aspx?FileName=" + ImgId;

    ImageFilePath.Add(ImgId, FilePath);


    img_.Height = Unit.Pixel(ImageHeigth);
    img_.Width = Unit.Pixel(ImageWidth);

    return img_;

   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:41:06+00:00Added an answer on June 1, 2026 at 6:41 pm

    You are not guarding your ImageFilePath.Add call. If the key already exists, you will get an exception saying as much.

    You can do a check for a key:

    if (ImageFilePath.ContainsKey(ImgId))
    {
        ImageFilePath[ImgId] = FilePath;
    }
    

    Or you can set on the index, this will add if it’s missing and update if it exists:

    ImageFilePath[ImgId] = FilePath;
    

    As opposed to calling Add.

    Note, however, that static members are liable to being lost when IIS recycles worker processes. Hence they tend to be avoided. There are also multi-threading issues as the static member is visible across the process.

    If you need a random file name, try DateTime.ToString("ddMMyyyyhhmmssfff") or Guid.NewGuid(), as opposed to keeping an instance of Random alive.

    Path also features a GetTempFileName method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been helping someone debug some code where the error message was Day
When i debug code contain SocketChannel write in Android, i got IllegalArgumentException, but the
I'm trying to debug code in Emacs but when I try either M-x gdb
I'm asking this, because when I try to debug code by using safari console,
Consider the code below: #if DEBUG if (Systems.Contains(system)) throw new InvalidOperationException(System already registered); #endif
Usually when I debug code an error occurs, visual studio stops on the line
My application has some debug code written specifically to send debug data to the
I am trying to debug code using gdb, but when I try to watch
Is there an easy way to debug code that is compiled during runtime with
sometimes i use debug code to alert something in javascript (for example, matching something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.