John Stagich's Blog

Microsoft .Net Developer

Enterpirse Library Cryptography Error

clock November 22, 2008 08:39 by author johnstagich

I was using the Cryptography portion Enterprise Library 3.1 for the encryption and decryption of data in my Windows application.  Part of the configuration process creates a key file (*.key) necessary for the encryption/decryption to work.

 It was all working fine until I tried to publish and deploy the application. The cryptography piece would not work when the application was deployed to another machine. Here is why. The algorithm that builds the key file uses local machine information to build the key.  When the key file is placed on another machine, the machine information is different; consequently the cryptography fails with the following error message: "Key not valid for use in specified state. \r\n" Source="System.Security" 

 How do you fix this problem?

 

1)      Create a password protected text version of the key file (for example, AppKey.txt). Use the Enterprise Library Application Configuration tool to create a text version of the key file (for example, AppKey.txt).

2)      When deploying your application, make sure you deploy the text version of your key file (AppKey.txt) and not the key file (AppKey.key).

3)      In your application, at start-up, add the following code I found on codeplex (see DevLingo entry July 17, 2007).  The code reads the text file (AppKey.txt) and recreates the key file (AppKey.key).  It then updates the app.config file, to point to the location of the new AppKey.key file.



PEX

clock November 21, 2008 09:10 by author johnstagich

At last night's Memphis .Net users group meeting, Mark Mydland from Microsoft talked about the up and coming enhancements to the testing portion of the next version of Visual Studio Team System. One of the new features that I liked was the ability to record a test sequence.

Another topic discussed was PEX.  It is a new product from Microsoft Research.  From the web page:

Right from the code editor, Pex finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage. Pex performs a systematic analysis, hunting for boundary conditions, exceptions and assertion failures, which you can debug right away.


November 2008 Quick Hits

clock November 8, 2008 13:42 by author johnstagich
  • Enterprise Library 3.1: Enterpise Library Configuation Editor Problem

An application I was working on needed to run on with the Entiprise 3.1 Library.  When I tried to use the Enterprise Library Configuration editor (EntlibConfig.exe) on my app.config file, I was getting errors that it could not locate the specific libraries/.dll’s.  The problem was that my libraries in my code where strongly named (PublicKeyToken=b77a5c561934e089) while the Enterprise Library Configuration Editory was looking for libraries with the PublicKeyToken set to null (PubliKeyToken=null).  The fix was to use the RIGHT Enterprise Library Configuration editor.  There are two of editors.  One resides in C:\EntLib3Src\App Blocks\bin and the other resided in  C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin.  The former works with non-signed libraries while the latter works with signed libraries.  From the Visual Studio Development environment, I changed app.config editor to point to the C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin editor.

For more information, check out this link from Tom Hollander on Avoiding Configuration pitfalls with incompatible copies of Enterprise Library.

  • How do you debug a Unit Test in Visual Studio 2008?

1) Set a breakpoint in your test, and then from the Visual Studio menu: Test-->Debug-->Tests in Current Context.

2) Set a breakpoint in your test. Go to the Test Results window (from the Visual Studio menu: Test-->Windows-->Test Results).  From the toolbar in the Test Results window, click on Debug drop down icon and then select Debug Checked Tests.

3) Try entering System.Diagnostics.Debugger.Launch() and System.Diagnostics.Debugger.Break() into your Unit Test code and then run your Unit Test  You then will be prompted with a Visual Studio Just-In-Time Debugger dialog box.  Select the default selection.  You should then break into your Unit Test code.

  • Here is a good link to the How Do I Video Series for Visual Basic.
  • For the datagrid view control, if you want the NewRowNeeded event to fire, the VirtualMode property for the datagrid view control needs to be set to true.
  • From Scott Mitchell's blog, I found out about a product called ELMAH that may come in handy down the road.  ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
  • Have you ever wanted to share a common file among project? Check out Sara Ford's tip number #365 that shows how to link a file. (I wonder how this works with Team Foundation Server Source Control?).  Tip number #364 is good too.  Visual Studio comes with an image library.

  • FromScott Gu's blog, new ASP.Net Chart control.

  • The table designer in Microsoft SQL 2005 I find is lacking because I cannot find a way to add properties to the columns displayed.  It only displays Column Name, Data Type, and Allow Nulls.  From Rich Strahl's Web log, comes a work around.  Use the Database Diagram Designer.   Right mouse click on the Database Diagrams folder and click New Database Diagram.  Next add your table.  Right mouse click on the table-->Table View-->Modify Custom...
     


About the author

I am the owner of Stagich Software Consulting.  Stagich Software Consulting specializes in developing Microsoft .Net/Microsoft SQL software applications.

 

Calendar

<<  July 2014  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Month List

Category list

None

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Sign In