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

  • SEARCH
  • Home
  • 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 6582077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:14:08+00:00 2026-05-25T16:14:08+00:00

public static class clsCounter { static int count; public static int Counter { get

  • 0
public static class clsCounter
{
    static int count;

    public static int Counter
    {
        get { return count; }
        set { count = value; }
    }
}

The above is the static class that is used to record a number.

Also, I have two projects within a VS2010 solution, one of which is a class library. In one of these classes, I have got the following code which uses clsCounter.

if (clsCounter.Counter == 0)
    countIES++;
else
    countIES = 0;

Now, in the other project, I set some new values to clsCounter

clsCounter.Counter = 50;

However, for some reason, I am not able to set clsCounter.Counter to 50, thus I always get countIES++. The code looks okay to me, and I have no idea what’s wrong with it? Can anyone help?

Thanks.

EDIT:

I wonder if it has something to do with the scope of projects within vs solution?

Solution Structure

Solution

  • ExcelAddIn

    • Form1.cs => (clsCounter.Counter = 50)
    • …
  • ClassLibrary

    • clsCounter => (static class)
    • …

EDIT 2:

clsCounter.Counter = 50; is actually running in backgroundworker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) event. Could this be a possible issue?

EDIT 3:

I have uploaded a sample project that seems to be able to reproduce the same problem. Here’s the shared link: => http://www.4shared.com/folder/sInyNWyi/_online.html

What I would like to do here is to populate a cell with value, Other case after the button ‘set value’ is pressed. The static class and UDF can be found in the class library.

Note that, to be able to use =testFunc() within excel addin, need to find it in automation server list and enable it. So just go File->Option->Addin->Under Manage Add-in->Click GO->Automation->Ebale ClassLibrary1.UDF

Please also check if the option “Register for COM interop” has been enabled or not before launching the debugger. To find it, go ClassLibrary1 Property -> Build -> Under Output, check Register for COM interop.

  • 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-05-25T16:14:08+00:00Added an answer on May 25, 2026 at 4:14 pm

    Finally, I think I found a workaround although it had nothing to do with the static. I was kinda inspired by the idea of using cookies in the web apps.

    Similarly, all I need to do here is:

    store a value in a temporary text file, by doing

    System.IO.File.WriteAllText(@"C:\countIESValue.txt", value);
    

    in the “set value” button click event handler.

    And read the stored value whenever I need it from the above text file and assign it to a local variable.

    if(System.IO.File.Exists(@"C:\countIESValue.txt"))
    {
        string val = System.IO.File.ReadAllText(@"C:\countIESValue.txt");
    }
    

    The text file can also be deleted after done processing. In this way, I don’t have to worry about any scope or application domain issues, although the permission of writing files is required. I am glad it worked pretty all right for me.

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

Sidebar

Related Questions

Consider: static class EntranceClass { public: static void RegisterSomething() { } static int main()
I have a static class that wraps some native methods from winspool: public static
I have a class that looks like this: public static class ReferenceData { public
Let's say that I've got the following class hierarchy : public static class Constants
public static class Extensions { public static T Include<T>(this System.Enum type,T value) where T:struct
I wrote this: public static class EnumerableExtensions { public static int IndexOf<T>(this IEnumerable<T> obj,
I have static class that holds some info public static class SampleDataCache { private
public static class stClass { static Class1 obj = new Class1(); public static int
Say that I have public static class M { public static string Concat(string a,
I have this register that registers all the objects I need: public static class

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.