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 7061025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:25:25+00:00 2026-05-28T04:25:25+00:00

I have an exe referencing a dll. In the dll there’s some methods, the

  • 0

I have an exe referencing a dll.

In the dll there’s some methods, the two we’re interested in are:

private static CacheItemPolicy _policy = new CacheItemPolicy();

[MethodImpl(MethodImplOptions.NoInlining)]
public static void SetValue(string Key, object Value)
{
    SetValue(Key, Value, _policy);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void SetValue(string Key, object Value, TimeSpan TTL)
{
    SetValue(Key, Value, GetPolicy(TTL));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static CacheItemPolicy GetPolicy(TimeSpan TTL)
{
    return new CacheItemPolicy()
    {
        SlidingExpiration = TTL
    };
}

In my exe when I try to call this method: using just cache.SetValue(key, item); it compiles and works fine, but when called using cache.SetValue(key, item, new TimeSpan(0, 1, 0)); I get the following exception:

Error 1 The type ‘System.Runtime.Caching.CacheItemPolicy’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

Why does the compiler say that I need to add this reference to an assembly that I’m not directly using in my code at this point?

I’m sure it’s something simple that I’m missing. I looked at Why do I need to reference a dll which I'm not using directly? but it refers to interfaces and that is not the case here.

Edit: there is also this:

protected static void SetValue(string Key, object Value, CacheItemPolicy Policy)
{
    // work is done here
}

But that’s protected and shouldn’t be visible to the calling exe.

Edit2: when this above SetValue that takes a CacheItemPolicy is set to private or internal, it works, why does protected (and protected internal) cause it to require the assembly?

  • 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-28T04:25:26+00:00Added an answer on May 28, 2026 at 4:25 am

    Since that static SetValue is protected, it’s visible to derived classes.

    So, if you can derive from the class (i.e. it’s public), then there’s a chance you could derive and use that method, meaning the reference is required.

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

Sidebar

Related Questions

When we have an exe or dll and a static library attached to it,
I have a .exe and many plug-in .dll modules that the .exe loads. (I
I have an EXE file using a DLL file which is using another DLL
I have a .exe file which I believe was created with VB6. Are there
I have two exe(A and B) files and a input(C) file. Firstly, The A
i have an exe loading a dll. i wrote both. i am dllexporting a
I have 3 assemblies written in C#, namely A.exe, B.dll, C.dll C.dll defines a
I have one exe which calls a dll.The code in dll needs to replace
Assume I have a class library project name Utilities.dll as follows: public static class
I have an exe that I know was written in java. I understand that

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.