locked
Microsoft Fakes doesn't generate System.Security.Cryptography members RRS feed

  • Question

  • Hi,

    I'm migrating some code from Microsoft Moles to Microsoft Fakes and everything seemed to work great only I have to migrate this line of code:

    MHashAlgorithm.AllInstances.ComputeHashByteArray = (HashAlgorithm algorithm, byte[] source) =>
    {
        byte[] copy = new byte[source.Length];
        Array.Copy(source, copy, source.Length);

        return copy;
    };

    Apparently it should be just replace MHashAlgorithm by ShimHashAlgorithm, but it didn't work. I used Object Browser to check what shims and stubs were generated and I found there isn't any for System.Security.Cryptography code.

    I have tried different configurations, from the default one that generates everything, to others more filtered and explictly requesting to generate members of this namespace. All without success.

    Do you know if there is any concrete restriction in Microsoft Fakes related to this namespace? Since insider it there are all kind of types (classes, interfaces, etc) and none of them appear in the Faked assembly.

    Just in case it is important, I'm using Visual Studio 2012 Premium with Update 2 CTP.

    Thanks for your help.

    Kind Regards,

    Javier.


    Si la respuesta es correcta, por favor márcala como correcta. También puedes votarla como útil si te lo ha sido.

    Tuesday, March 19, 2013 11:18 AM

All replies

  • A little bit more info:

    I activated "diagnostics" and this is the warning Fakes returns when trying to create the shim type of HashAlgorithm:

    mscorlib.fakes : warning : Cannot generate shim for System.Security.Cryptography.HashAlgorithm: type is not supported because it is not available or changed between versions.


    Si la respuesta es correcta, por favor márcala como correcta. También puedes votarla como útil si te lo ha sido.

    Tuesday, March 19, 2013 12:12 PM
  • Hi,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 20, 2013 1:32 AM
  • Hello Javier,

    HashAlgorithm class is located in the mscorlib.dll assembly. Please make sure you select the correct reference to add the Fake assembly.

    If it is not the cause, please start VS as local administrator, and change the fakes file to:

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="mscorlib" Version="4.0.0.0"/>
      <StubGeneration>
        <Clear/>
      </StubGeneration>
      <ShimGeneration>
        <Clear/>
        <Add FullName="System.Security.Cryptography"/>
      </ShimGeneration>
    </Fakes>

    Thanks & Regards,

    Jian-Wei Yu [MSFT]

    Microsoft Online Community Support


    --------------------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

     

    Thursday, March 21, 2013 6:55 AM
  • Hi Jian-Wei,

    I have tried your solution but it doesn't work. In the picture you can see the result, from Object Explorer, for the "faked" mscorlib.

    objectexplorer

    And this is the content of mscorlib.fakes:

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="mscorlib" Version="4.0.0.0"/>
      <StubGeneration>
        <Clear/>
      </StubGeneration>   
      <ShimGeneration>
        <Clear/>
        <Add FullName="System.Security.Cryptography"/>   
      </ShimGeneration>
    </Fakes>

    Let me know if you need any extra info.

    Thanks.

    Kind Regards,

    Javier


    Si la respuesta es correcta, por favor márcala como correcta. También puedes votarla como útil si te lo ha sido.

    Thursday, March 21, 2013 12:27 PM
  • Hello Javier,

    Please open VS as local administrator. (Right click Visual Studio 2012, Run as administrator), change the fakes file to:

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
      <Assembly Name="mscorlib" Version="4.0.0.0"/>
      <StubGeneration>
        <Clear/>
      </StubGeneration>
      <ShimGeneration>
        <Clear/>
        <Add FullName="System.Security.Cryptography"/>
      </ShimGeneration>
    </Fakes>

    Rebuild whole solution. Any difference? 

    If not, there is some issue on your machine, you may require a more in-depth level of support. Please visit the below link to see the various paid support options that are available to better meet your needs.

    http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Thanks & Regards,

    Jian-Wei Yu [MSFT]

    Microsoft Online Community Support

    --------------------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Friday, March 22, 2013 7:30 AM
  • Hell Jian-Wei,

    I tried your suggestion, but it didn't work, which is not a surprise since it is the same solution, but adding the "Diagnostic" flag.

    For your interest, this is the warning I'm getting in Output window for the class I want to "fake":

    warning : Cannot generate shim for System.Security.Cryptography.HashAlgorithm: type is not supported because it is not available or changed between versions. 

    This is not the only message of this type I see in the Output window. There are a lot for other classes, which is not a surprise since almost none of the classes in the assembly is getting is corresponding "fake" class.

    About the suggestion it may be a problem in my machine, I don't know. I have installed here several versions of Visual Studio (2008, 2010, 2012) and other stuff the last 2 years. I don't know if that could be a problem, but I think it shouldn't. Apart from that, I have been able to "fake" successfully a lot of other assemblies, either from .NET FX and for internal projects.

    Kind Regards,

    Javier.


    Si la respuesta es correcta, por favor márcala como correcta. También puedes votarla como útil si te lo ha sido.

    Friday, March 22, 2013 9:10 AM