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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:23:21+00:00 2026-05-15T07:23:21+00:00

I like to adhere to StyleCop’s formatting rules to make code nice and clear,

  • 0

I like to adhere to StyleCop’s formatting rules to make code nice and clear, but I’ve recently had a problem with one of its warnings:

All using directives must be placed
inside of the namespace.

My problem is that I have using directives, an assembly reference (for mocking file deletion), and a namespace to juggle in one of my test classes:

using System;
using System.IO;
using Microsoft.Moles.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[assembly: MoledType(typeof(System.IO.File))]

namespace MyNamespace
{
//Some Code
}

The above allows tests to be run fine – but StyleCop complains about the using directives not being inside the namespace.

Putting the usings inside the namespace gives the error that “MoledType” is not recognised.

Putting both the usings and the assembly reference inside the namespace gives the error

‘assembly’ is not a valid attribute
location for this declaration. Valid
attribute locations for this
declaration are ‘type’. All attributes
in this block will be ignored.

It seems I’ve tried every layout I can but to no avail – either the solution won’t build, the mocking won’t work or StyleCop complains!

Does anyone know a way to set these out so that everything’s happy? Or am I going to have to ignore the StyleCop warning in this case?

  • 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-15T07:23:22+00:00Added an answer on May 15, 2026 at 7:23 am

    Solved two minutes later!

    I just needed to put the full path of “MoledType” in the assembly reference – meaning I could leave it outside of the namespace with the using directives inside like so:

    [assembly: Microsoft.Moles.Framework.MoledType(typeof(System.IO.File))]
    namespace MyNamespace
    {
    using System;
    using System.IO;
    using Microsoft.Moles.Framework;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    // Some Code...
    }
    

    Hopefully someone’ll find this useful!

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

Sidebar

Related Questions

I'd like to adhere to the Don't-Repeat-Yourself principle, but sometimes when I write PHP
Like in topic. It is possible to do it? Or make something to use
Like a person asked here (but his solutions as to call a nother function)
while doing some static code analysis I've found a weird one. On a call
I'm continuing to learn C and would like to adhere to whatever is the
To adhere to 1st normal form, one of the things you must avoid is
I would like to know the rules specified by the C++ language standard for
Like setFont(QFont(Helvetica,16,1)) ,I want to summerize these fonts.However,I dont't know how many fonts there
Like the title says I'm having some trouble printing out symbol codes and their
Like many others Knockout developers before me, I encountered a slow running script warning

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.