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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:18:35+00:00 2026-05-26T22:18:35+00:00

When running code analysis on my MVC3 project that uses Ninject, I receive the

  • 0

When running code analysis on my MVC3 project that uses Ninject, I receive the following warning:

Warning 1 CA2000 : Microsoft.Reliability : In method
‘NinjectMVC3.CreateKernel()’, object ‘kernel’ is not disposed along
all exception paths. Call System.IDisposable.Dispose on object
‘kernel’ before all references to it are out of scope.

I understand I can easily suppress the message but am curious if there is a better way to resolve the warning. The static method is obviously meant to return ‘kernel’ so one should not dispose of it.

    private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        RegisterServices(kernel);
        return kernel;
    }

Not a major problem, just a learning exercise.

  • 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-26T22:18:35+00:00Added an answer on May 26, 2026 at 10:18 pm

    The problem that CA2000 is detecting here is that the instantiated object will be “orphaned” without disposition if an exception is thrown between its instantiation and its return from the method. In most cases, I would tend to consider the cure to be worse than the problem for such scenarios. However, if you wish to fix it and use of the approach suggested by Darin is not an option, here’s an alternate version that should pass CA2000 verification:

    private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel();
        try
        {
            RegisterServices(kernel);
            return kernel;
        }
        catch
        {
            kernel.Dispose();
            throw;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When running code analysis on my project, I receive the following message: CA1051 :
Running code analysis on the following action results in a CA1062 warning, advising I
I am running static code analysis with FxCop 1.36 and I keep getting warning
Previously, when running a Code Analysis on my project, I thought the context men
I'm running a full code analysis on my project, and it says it has
I was running discriminant analysis using R. The code is the following: fit <-
I'm running code that sometimes yields this: UInt32 current; int left, right; ... //sometimes
I have a thread in my application that is running code that can potentially
I am running simulation code that is largely bound by CPU speed. I am
I have the following code running on my Android device. It works great and

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.