Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 155 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

Possible Duplicate:
Incomprehensible “Your post appears to contain code that is not properly formatted as code” error

I get the Oops! code message when submitting the question below, any idea why?

Oops! Your question couldn't be submitted because:

Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.

Moq throws a TypeInitializationException when using Moles with the [HostType("Moles")]. Code example and exception below. 


    [TestMethod]
    [HostType("Moles")]
    public void TestMethod()
    {
        var mock = new Mock<IAnything>();
    }

The exception:

<pre>
System.TypeInitializationException occurred
  Message=The type initializer for 'Moq.Extensions' threw an exception.
  Source=Moq
  TypeName=Moq.Extensions
  StackTrace:
       at Moq.Extensions.IsMockeable(Type typeToMock)
       at Moq.Mock`1.CheckParameters()
       at Moq.Mock`1..ctor(MockBehavior behavior, Object[] args)
       at Moq.Mock`1..ctor(MockBehavior behavior)
       at Moq.Mock`1..ctor()
       at BP.DFR.Common.Services.Network.DfrNetworkQueryTests.MyTestMethod()
  InnerException: System.Security.VerificationException
       Message=Operation could destabilize the runtime.
       Source=Moq
       StackTrace:
            at Moq.Extensions..cctor()
       InnerException:
</pre>


The link below suggested it might be a moq version issue, but it happens in both version 3.1 and 4.0 for me.

http://code.google.com/p/moq/issues/detail?id=344

I'm using VS 2010 Premium SP1. Anybody had any luck resolving this?
share|improve this question

marked as duplicate by Al E., Brad Mace, amanaP lanaC A nalP A naM A, Daniel DiPaolo, jonsca Aug 10 '12 at 16:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I've also tried escaping the [HostType("Moles")] with backticks, but no joy. – SDK Aug 13 '12 at 8:15
up vote 4 down vote accepted

Looking at your code, you probably haven't indented below line properly:

System.TypeInitializationException occurred

You need to indent your code by four spaces, or select it all and press the {} button. Also make sure there is one blank line between your last line of text and your first line of code. This will cause your code to be rendered in <pre><code> blocks and all of its HTML/Markdown entities will be escape/ignored respectively.

Properly indented code renders like this:

#include <iostrea>

int main() {
  vector<int> items;
}

Unindented code renders like this:

include

int main() { vector items; }

You can see why we stress proper indenting of code.

share|improve this answer
    
No, the part of the code beginning with System.TypeInitializationException occurred is within a <pre> block, that works too. – Gilles Aug 10 '12 at 16:32
    
Yip the System.TypeInitializationException is not code, just an exception message, that's why I put in the <pre> block. I don't know if it has something to do with the [HostType("Moles")] in the first line being seen as code. But I don't really want that line as code. Thanks for the reply, still no joy though :( – SDK Aug 11 '12 at 10:11
    
I didn't actually try your suggestion, thought Gilles was correct with his comment. But you're right the exception message needs to be indented. I wouldn't have considered it code, but hey. Thanks. – SDK Aug 13 '12 at 8:23

Not the answer you're looking for? Browse other questions tagged .