Navigation

Showing posts with label VBTips. Show all posts
Showing posts with label VBTips. Show all posts

Thursday, December 22, 2011

Does it take forever for you Visual Studio 2010 Xaml Designer to load?

If opening a xaml file in the designer is painstakingly slow you can dramatically improve the load time by simply turning off “Automatically Populate Toolbox Items”.

image

image

Wednesday, June 08, 2011

How to control the scrollbar position in a Tree View Control

Loading nodes into a tree view control that expand past the viewable area of the tree view can cause the scroll bars to move and display the content of the control incorrectly as in figure 1.

image

Figure 1

To control the position of the scrollbars you can use the following code which will result in the tree view displaying properly as in figure 2.

Imports System.Runtime.InteropServices

Public Class Form1
    <DllImport("user32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
    Public Shared Function GetScrollPos(ByVal hWnd As Integer, ByVal nBar As Integer) As Integer
    End Function
    <DllImport("user32.dll")> _
    Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer
    End Function
    Private Const SB_HORZ As Integer = &H0
    Private Const SB_VERT As Integer = &H1

    Dim t As Boolean = False

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If t = False Then
                t = True
                Me.TreeView1.ExpandAll()
            Else
                t = False
                Me.TreeView1.CollapseAll()
            End If


            'Dim ScrollPos As Point = GetTreeViewScrollPos(Me.TreeView1)
            '   Function sets the position of the treeview you pass

        Catch ex As Exception

        End Try
    End Sub
    ''' <summary>
    ''' Gets the current position of the scroll
    ''' </summary>
    ''' <param name="treeView"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetTreeViewScrollPos(ByVal treeView As TreeView) As Point
        GetTreeViewScrollPos = New Point(0, 0)
        Try
            GetTreeViewScrollPos = New Point(GetScrollPos(CInt(treeView.Handle), SB_HORZ), GetScrollPos(CInt(treeView.Handle), SB_VERT))
        Catch ex As Exception

        End Try
        Return GetTreeViewScrollPos
    End Function
    ''' <summary>
    ''' Sets the position of the scroll of passed treeview control
    ''' </summary>
    ''' <param name="treeView"></param>
    ''' <param name="scrollPosition"></param>
    ''' <remarks></remarks>
    Private Sub SetTreeViewScrollPos(ByRef treeView As TreeView, ByRef scrollPosition As Point)
        Try
            SetScrollPos(DirectCast(treeView.Handle, IntPtr), SB_HORZ, scrollPosition.X, True)
            SetScrollPos(DirectCast(treeView.Handle, IntPtr), SB_VERT, scrollPosition.Y, True)
            If treeView.Nodes.Count > 0 Then
                Dim currentNode As TreeNode = treeView.Nodes(0) 'treeView.GetNodeAt(0, 0)
                currentNode.EnsureVisible()
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SetTreeViewScrollPos(Me.TreeView1, New Point(0, 0))
    End Sub
End Class

Friday, February 25, 2011

Productivity Power Tools introduces Find, Organize Imports for VB, Enhanced Scrollbar, Middle-Click Scrolling and more!

MS has released an updated version of the productivity power tools.

http://blogs.msdn.com/b/visualstudio/archive/2011/02/22/productivity-power-tools-introduces-find-organize-imports-for-vb-enhanced-scrollbar-middle-click-scrolling-and-more.aspx

Resetting Your Extensions for the Last Time!

We've heard a great deal of feedback on how each update of the Productivity Power Tools re-enables all of the extensions when it installs. If you are careful about installing the Power Tools via the extension manager or as long as an instance of Visual Studio is running, this version of the Productivity Power Tools will be the last which resets the extensions.

Please note: If you are running Visual Studio 2010 SP1 (Beta) that you will need to uninstall previous versions of the Productivity Power Tools prior to upgrading due to a change in the digital signature for the Power Tools

Find

There are many different ways to find within Visual Studio (Incremental Search, Quick Find, Find in Files, Find Toolbar, etc) and it often isn’t clear which is the best for a given task or worse these options even exist.  The find dialog itself also can obstruct code and jump around while users are searching. Our solution to these problems is the new Find extension. In the screenshot below, you will see that we’ve turned the quick find & incremental search experiences into a find pop-up that is available at top right hand corner of the editor. After hitting, Ctrl+I or Ctrl+F, it simply highlights the find results as you type.  From this small but powerful pop-up, you have access to most of the Quick Find functionality such as replace, options to match case and added support for matching .NET Regular Expressions!

Release notes:

  • As an extension, it was only possible to implement these changes for the code editor. You still must use Quick Find for searching in designers and other non-editor tabs. 
  • .NET Regular expressions are only available in the Find extension. Find in Files will continue to use VS Regular expressions
  • Feel free to email us your feedback: VSFindFeedback@microsoft.com

Enhanced Scrollbar

We’ve been looking into ways that we can improve the experience of navigating through code files.  Our solution is the source map which has three modes that will allow you to more easily see the interesting artifacts in your files (edits, breakpoints, bookmarks, errors, warnings etc) and make it easy for you to navigate between them.  The default mode is the “scroll bar only mode” which overlays icons onto the standard scrollbar to allow for viewing of these artifacts.  In the source map mode, we’ve replaced the default scroll bar allow you to click on any item on the scrollbar to navigate directly to it. This source map mode also provides a preview of the part of the document as you hover.  Finally, we have the detailed source map mode, which allows you to get a zoom out view of your entire file.  You can switch between any of these modes by right-clicking on the scroll bar or going to Tools Options>Productivity Power Tools>Source Map where we have a host of other options that you can configure.

Middle-Click Scrolling

The ability to do middle click scrolling in Visual Studio 2010 has been a top request from our beta customers that we weren’t quite able to get into the release. With this extension you can press down on your scroll wheel and the move the mouse to quickly scroll through your document!

Organize Imports for Visual Basic

As part of theco-evolution strategy for Visual Basic and C#, we continue to bring the best features from each language experiences to the other. With Organize Imports for Visual Basic we’ve added yet another feature to that list.  From the context menu, it allows you to sort the imports logically and remove the ones that aren’t being used.

Add Reference Support for Multi-Targeting

“How come I can’t add a reference to System.Web?”  Many users have scratched their heads trying to figure out why certain dlls aren’t showing up in the Add Reference dialog. The confusion has been caused by the logic in the Add Reference dialog which filters out assemblies that are not valid on the .NET Client Profile which many of Visual Studio templates target by default.  The Productivity Power Tools solution is to grey out the assemblies which are not available in the current framework profile. When you try to add them, it will automatically prompt you to re-target to a profile of the same framework which does support them.

Options in HTML Cut/Copy

Productivity Power Tool users have asked for the ability to tweak the html format which gets copied to the clipboard and with the release you now have the ability to customize that to suite your needs.  Simply go to Tools Options>Productivity Power Tools> HTML Copy

This release of the extension also fixes the commonly reported bug where Cut/Copy occasionally fail which was fixed in VS 2010 SP1 Beta but was present in the October release of the Productivity Power Tools.

Wednesday, November 17, 2010

Must have Visual Studio Tools

Below are a list of must have Visual Studio Tools.  They are all free and from Microsoft!
Visual Studio 2010 Feature Packs http://msdn.microsoft.com/en-us/vstudio/ff655021.aspx
Feature Packs enable you to extend Visual Studio 2010 with capabilities that enhance and complement the existing tools.
Visual Studio 2010 Feature Pack 2 (MSDN Subscribers Only) Cumulative feature pack that extends testing, code visualization and modeling capabilities in Visual Studio 2010.
Testing features:
Use Microsoft Test Manager to capture and playback action recordings for Silverlight 4 applications.
Create coded UI tests for Silverlight 4 applications with Visual Studio 2010 Premium or Visual Studio 2010 Ultimate.
Edit coded UI tests using a graphical editor with Visual Studio 2010 Premium or Visual Studio 2010 Ultimate.
Use action recordings to fast forward through manual tests that need to support Mozilla Firefox 3.5 and 3.6.
Run coded UI tests for web applications using Mozilla Firefox 3.5 and 3.6 with Microsoft Visual Studio 2010 Premium or Visual Studio 2010 Ultimate.
Code visualization and modeling features (requires Visual Studio 2010 Ultimate):
Use the Generate Code command to generate skeleton code from elements on UML class diagrams. You can use the default transformations, or you can write custom transformations to translate UML types into code.
Create UML class diagrams from existing code.
Explore the organization and relationships in C, C++, and ASP.NET projects by generating dependency graphs.
Import elements from UML sequence diagrams, class diagrams, and use case diagrams as XMI 2.1 files that are exported from other modeling tools.
Create links and view links from work items to model elements.
Create layer diagrams from C or C++ code and validate dependencies.
Write code to modify layer diagrams and to validate code against layer diagrams.

Productivity Power Tools http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef
A set of extensions to Visual Studio Professional (and above) which improves developer productivity. In this third major release of the Power Tools we have made significant improvements to the Solution Navigator and the Tab Well to address our top customer requests.
PowerCommands for Visual Studio 2010 http://visualstudiogallery.msdn.microsoft.com/en-us/e5f41ad9-4edc-4912-bca3-91147db95b99
PowerCommands 10.0 is a set of useful extensions for the Visual Studio 2010 adding additional functionality to various areas of the IDE. Visit the VSX Developer Center at http://msdn.com/vsx for more information about extending Visual Studio.

Friday, August 20, 2010

VS2010 Toolbox Search

Have you ever wanted to be able to search the VS2010 toolbox for the control your looking for?  Well you can!

The visual studio team has added the ability to search for controls in the toolbox by name.  To use it, put focus in the toolbox (by clicking in it, for example) and then start typing the name of the control you want to find.  As you type, the selection will move to the next item that matches what you've typed so far.  The text you've typed is shown in the status bar, like this:
You can hit Backspace if you mistyped a character, or Tab to go to the next match for the current string.  To cancel the search, you can hit Escape, move the selection, or click on another window.

You can also collapse all the groups by pressing "/" (and you can expand them all with "*")

Thursday, August 12, 2010

Visual Studio 2010 Bug; "Insufficient avaiable memory to meet the expected demands..." on cut and paste!

If you’re getting the error below on cut-n-paste operations there is a patch for it.  You can download the patch from Microsoft's visual studio blog website at http://jpda.me/9bRy9v.

"Microsoft Visual Studio" "Insufficient available memory to meet the expected demands of an operation at this time, possibly due to virtual address space fragmentation. Please try again later."

Wednesday, July 28, 2010

Free Useful web Tools for Developers

The following links are some great free tools

1.  Convert Files

Easily convert different file formats. You can convert images, download YouTube video and much more with this web tool.

http://www.convertfiles.com/

2.  Joongel

Are you a power searcher? Then this tool this for you. You simultaneously search different search engines in different categories. It can be very useful if you are doing an online research.

http://www.joongel.com/

3.  Quick Thumnail

Simply create thumbnails in different sizes right from your browser. You can upload an image from your computer or web directory and choose sizes of the thumbnails you want.

http://quickthumbnail.com/

4.  ScreenCastle

Free screen cast application very light weight.

http://screencastle.com/

5.  DevCheatSheet

Google for hours for cheat sheet you saw last week. You can find it in DevCheatSheets.com

http://devcheatsheet.com/

Tuesday, July 27, 2010

Class Designer PowerToys for Visual Studio 2010 is Released

Class Designer PowerToys for Visual Studio 2010 is released today! It provides a bunch of enhancements to Visual Studio 2010 Class Designe.
It has many cool features like pan/zoom window, floating properties window, fast navigation, etc. You could find the detailed feature list in its help document which is available on the desktop after the Class Designer PowerToys is installed.
Besides the binary, the source code is also available. You could extend the PowerToys easily.
This set of add-ins augments existing functionality in the Visual Studio Class Designer and the Distributed Systems Designers. It now supports Visual Studio 2005, Visual Studio 2008 and Visual Studio 2010. The Design Tools Enhancements add-in provides a common set of features that can be used by both the Class Designer and the Distributed System Designers, such as pan/zoom window and rich formatting commands. The Class Designer Enhancements add-in provides additional functionality for the Visual Studio Class Designer, such as HTML export and nested type creation commands. This download includes all necessary source code and a Visual Studio project template for creating your own add-ins for the Visual Studiodesigners. The Class Designer is a developer productivity tool available in Visual Studio Standard Edition and above, which allows developers to easily visualize, design, refactor, and document their code. The Distributed System Designers enable software architects, operations managers, and developers to visually design service-oriented solutions and validate them at design time against their operational environments. The Distributed System Designers are a core component of Visual Studio Team Edition for Software Architects and the Visual Studio Team System.
http://modeling.codeplex.com/releases/view/49473

Friday, June 25, 2010

Access WCF Service by WEBGet from Browser

If you want to expose a simple web service (WCF) so that it can be accessed by a web get or browser you need to first insure that the input and output are simple data types like strings or integers.

1.Create the web site project

2.  Add a reference to System.ServiceModel.Web (so we can access the WebGet decleration.

3.  Add your function and decerate it with the following;

<OperationContract()> _
    <WebGet()> _
    Function Dosmothing(ByVal pValue As String) As String




4.  Add the following to your web.config file;



 <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>


 



5.  Update your service model to reflect the one below. 



<system.serviceModel>
<behaviors>
   <endpointBehaviors>
    <behavior name="NewBehavior">
     <webHttp />
    </behavior>
   </endpointBehaviors>
   <serviceBehaviors>
    <behavior name="my.Application.Behavior1">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
<services>
   <service behaviorConfiguration="Behavior1"
    name="myInterface">
    <endpoint behaviorConfiguration="NewBehavior" binding="webHttpBinding"
     bindingConfiguration="" contract="myInterface" />
   </service>
  </services>
</system.serviceModel>


6.Now you can access the function like this;


http://localhost:54433/myInterface.svc/DoSmothing?pValue=Smothing

Wednesday, June 23, 2010

Converting Image to String and Back in Base64

When you need to store an image as string for say xml transmission you will need to transfer it back and forth from base64 encoding.

 

 

Public Function ImageToBase64(image As Image, format As System.Drawing.Imaging.ImageFormat) As String
    Using ms As New MemoryStream()
        ' Convert Image to byte[]
        image.Save(ms, format)
        Dim imageBytes As Byte() = ms.ToArray()

        ' Convert byte[] to Base64 String
        Dim base64String As String = Convert.ToBase64String(imageBytes)
        Return base64String
    End Using
End Function

 

Public Function Base64ToImage(base64String As String) As Image
    ' Convert Base64 String to byte[]
    Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
    Dim ms As New MemoryStream(imageBytes, 0, imageBytes.Length)

    ' Convert byte[] to Image
    ms.Write(imageBytes, 0, imageBytes.Length)
    Dim image__1 As Image = Image.FromStream(ms, True)
    Return image__1
End Function

Convert MemoryStream to String and String to MemoryStream

These functions allow you to swap strings and memory streams back and forth.

 

Public Shared Function GetMemoryStreamFromString(ByVal s As String) As IO.MemoryStream
        If s Is Nothing OrElse s.Length = 0 Then
            Return Nothing
        End If

        Dim m As New IO.MemoryStream()
        Dim sw As New IO.StreamWriter(m)
        sw.Write(s)
        sw.Flush()

        Return m
    End Function


 



    Public Shared Function GetStringFromMemoryStream(ByVal m As IO.MemoryStream) As String
        If m Is Nothing OrElse m.Length = 0 Then
            Return Nothing
        End If

        m.Flush()
        m.Position = 0
        Dim sr As New IO.StreamReader(m)
        Dim s As String = sr.ReadToEnd()
        Return s
    End Function

Tuesday, June 22, 2010

PowerCommands for Visual Studio 2010

This is a must have for the VB.net 2010 developer!

http://bit.ly/9SOxFl

PowerCommands 10.0


PowerCommands 10.0 is a set of useful extensions for the Visual Studio 2010 adding additional functionality to various areas of the IDE. Visit the VSX Developer Center at http://msdn.com/vsx for more information about extending Visual Studio.

Below is a list of the commands included in PowerCommands for Visual Studio 2010 version 10.0.

Enable/Disable PowerCommands in Options dialog

This feature allows you to select which commands to enable in the Visual Studio IDE. Point to the Tools menu, then click Options. Expand the PowerCommands options, then click Commands. Check the commands you would like to enable.

Note: All power commands are initially defaulted Enabled.

Format document on save / Remove and Sort Usings on save

The Format document on save option formats the tabs, spaces, and so on of the document being saved. It is equivalent to pointing to the Edit menu, clicking Advanced, and then clicking Format Document. The Remove and sort usings option removes unused using statements and sorts the remaining using statements in the document being saved.

Note: The Remove and sort usings option is only available for C# documents.

Note: Format document on save and Remove and sort usings both are initially defaulted OFF.

Clear All Panes

This command clears all output panes. It can be executed from the button on the toolbar of the Output window.


Copy Path

This command copies the full path of the currently selected item to the clipboard. It can be executed by right-clicking one of these nodes in the Solution Explorer:

The solution node; A project node; Any project item node; Any folder.


Email CodeSnippet

To email the lines of text you select in the code editor, right-click anywhere in the editor and then click Email CodeSnippet.


Insert Guid Attribute

This command adds a Guid attribute to a selected class. From the code editor, right-click anywhere within the class definition, then click Insert Guid Attribute.


Show All Files

This command shows the hidden files in all projects displayed in the Solution Explorer when the solution node is selected. It enhances the Show All Files button, which normally shows only the hidden files in the selected project node.


Undo Close

This command reopens a closed document , returning the cursor to its last position. To reopen the most recently closed document, point to the Edit menu, then click Undo Close. Alternately, you can use the CtrlShiftZ shortcut.

To reopen any other recently closed document, point to the View menu, click Other Windows, and then click Undo Close Window. The Undo Close window appears, typically next to the Output window. Double-click any document in the list to reopen it.


Collapse Projects

This command collapses a project or projects in the Solution Explorer starting from the root selected node. Collapsing a project can increase the readability of the solution. This command can be executed from three different places: solution, solution folders and project nodes respectively.


Copy Class

This command copies a selected class entire content to the clipboard, renaming the class. This command is normally followed by a Paste Class command, which renames the class to avoid a compilation error. It can be executed from a single project item or a project item with dependent sub items.


Paste Class

This command pastes a class entire content from the clipboard, renaming the class to avoid a compilation error. This command is normally preceded by a Copy Class command. It can be executed from a project or folder node.


Copy References

This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes.


Paste References

This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node.


Copy As Project Reference

This command copies a project as a project reference to the clipboard. It can be executed from a project node.


Edit Project File

This command opens the MSBuild project file for a selected project inside Visual Studio. It combines the existing Unload Project and Edit Project commands.


Open Containing Folder

This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node


Open Command Prompt

This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively.


Unload Projects

This command unloads all projects in a solution. This can be useful in MSBuild scenarios when multiple projects are being edited. This command can be executed from the solution node.


Reload Projects

This command reloads all unloaded projects in a solution. It can be executed from the solution node.


Remove and Sort Usings

This command removes and sort using statements for all classes given a project. It is useful, for example, in removing or organizing the using statements generated by a wizard. This command can be executed from a solution node or a single project node.


Extract Constant

This command creates a constant definition statement for a selected text. Extracting a constant effectively names a literal value, which can improve readability. This command can be executed from the code editor by right-clicking selected text.


Clear Recent File List

This command clears the Visual Studio recent file list. The Clear Recent File List command brings up a Clear File dialog which allows any or all recent files to be selected.


Clear Recent Project List

This command clears the Visual Studio recent project list. The Clear Recent Project List command brings up a Clear File dialog which allows any or all recent projects to be selected.


Transform Templates

This command executes a custom tool with associated text templates items. It can be executed from a DSL project node or a DSL folder node.


Close All

This command closes all documents. It can be executed from a document tab.

Wednesday, June 02, 2010

Windows Mobile Client Development (OS 5) Logging with Nlog

I just completed a windows mobile client application targeting a 5.1 mobile OS.  This project provided the ability to scan a barcode with the embedded barcode scanner, return the selected item from a web service (along with a photo stored on a network share) and allow the user to post movement and status changed on the scanned item.

This was the first time I used NLog on a Compact Framework device and after getting use to some of the minor issues related to the OS was able to use NLog just like a VB.net application.

In this project I configured Nlog via code rather then a configuration file.  The first issue was getting the application path to pass to Nlog.

First, I created a global variable to save the path and the Nlog logger;

Public gApplicationPath As String = String.Empty

Public gLogger As NLog.Logger = Nothing

 

Next I set the path with the following statement;

gApplicationPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

The configuration was simple with the following code;

NLog.Internal.InternalLogger.LogFile = gApplicationPath & "\nlog.txt"
NLog.LogManager.ThrowExceptions = False

Dim config As New NLog.Config.LoggingConfiguration
Dim filetarget As New NLog.Targets.FileTarget
With filetarget
    .Name = "filetarget"
    .FileName = gApplicationPath & "\ErrorLog.txt"
    .Layout = "${longdate}||${level}||${logger}|||${message}|${exception:format=message:separator=*}^"
End With
config.AddTarget("file", filetarget)
Dim rule1 As New NLog.Config.LoggingRule("*", NLog.LogLevel.Trace, filetarget)
config.LoggingRules.Add(rule1)
NLog.LogManager.Configuration = config
gLogger = LogManager.GetLogger("myLogerName")

Pretty straightforward!

I am a big fan of targeting a database to store the logging data to and will address updating the application to use that target next time.

Wednesday, May 26, 2010

ILMerge v2.10.0526 Released

Mike Barnett who leads the ILMerge group at Microsoft just released an updated version of ILMerge which is a great tool for merging multiple dot net assemblies into a single assembly.

Link to ILMerge Site http://bit.ly/do1LJe

Link to download http://bit.ly/nXpWJ

Thursday, May 13, 2010

MSBuildShellExtension – Build .Net projects from Windows Explorer!

MSBuildShellExtension lets you build .NET projects without ever opening Visual Studio or the command prompt. MSBuild targets can be executed from your favorite file system tool like Windows Explorer or Total Commander. The possibility to extend MSBuildShellExtension with your own targets and editors, makes it a very flexible and useful tool for all .NET developers.

image

http://msbuildshellex.codeplex.com/

Vb to C# or C# to VB Coder Converter

Here are a few sites that will convert VB and c# code back and forth. 

http://converter.telerik.com/

http://www.developerfusion.com/tools/convert/csharp-to-vb/

http://www.carlosag.net/Tools/CodeTranslator/

Credit to Scott Hansleman’ss blog for these links.

Wednesday, May 12, 2010

Jarek Kowalski – Nlog Founder

I have been using Nlog for a number of years and find it to be a great logging component.  Today my post on loadFromRemoteSources which deals with referencing assemblies from remote network shares in VS2010 was re-tweeted by Jarek on his twitter page!

http://twitter.com/JarekKowalski

image

loadFromRemoteSources

With VS2010 adding references to your application from a network drive such as nLog can result in this error;

System.IO.FileLoadException
Could not load file or assembly 'NLog, Version=1.0.0.505, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

This is a result of the default loadFromRemoteSources behavior of VS2010.  This directive specifies whether assemblies from remote sources should be granted full trust.
In the .NET Framework version 3.5 and earlier versions, if you loaded an assembly from a remote location, the assembly would run partially trusted with a grant set that depended on the zone in which it was loaded. For example, if you loaded an assembly from a Web site, it was loaded into the Internet zone and granted the Internet permission set. In other words, it executed in an Internet sandbox. If you try to run that assembly in the .NET Framework version 4, an exception is thrown; you must either explicitly create a sandbox for the assembly, or run it in full trust.

The <loadFromRemoteSources> element lets you specify that the assemblies that run partially trusted in earlier versions of the .NET Framework should be run fully trusted in the .NET Framework 4.
Adding the following to your app.config and C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config will resolve the issue;

<configuration>
  <runtime>
    <loadFromRemoteSources enabled="true"/>
  </runtime>
</configuration>

Wednesday, May 05, 2010

How to trap Nlog events within your application

Being able to trap nLog log events within your application allows you to provide a default msg to your users without having to have the UI code everywhere in your application. 

This post describes how to setup nLog with an additional target that will fire an event in your application that you can then capture.

First there are a few changes to the log file;

image

Notice that we added a new target and rule for that target.  Next we need to add a class with a shared method to capture the event;

image

This allows you to catch the log event.