How to solve: Microsoft Visual Studio 2008 designer hangs after installing Microsoft Office 2010 and Microsoft Visual Studio 2010

If you install Microsoft Office 2010 and Microsoft Visual Studio 2010 on an machine running Microsoft Visual Studio 2008 and Microsoft Office 2007, you might run into the problem that the designer of the Microsoft Visual Studio 2008 hangs. To resolve this problem restore the Microsoft Visual Studio Web Authoring Component:

http://blog.hinshelwood.com/archive/2009/07/19/office-2010-gotcha-2-visual-studio-2008-locks.aspx

How to determine if a given path is a relative path in C#

If you want to determine if a given path is a relative path in C#, you can use the System.IO.Path.IsPathRooted function:

bool isPathRooted = Path.IsPathRooted("Test.txt");
Console.WriteLine(isPathRooted);

Result: False

bool isPathRooted = Path.IsPathRooted(@"\\nas\Test.txt");
Console.WriteLine(isPathRooted);

Result: True

bool isPathRooted = Path.IsPathRooted(@"C:\Test.txt");
Console.WriteLine(isPathRooted);

Result: True

How to resolve: SSIS package won’t stop debugger on script task

When you are on a x64 machine and de business intellegence studio doesn’t stop the debugger in you’re script task on the break points, set you’re package to x86 (Run64BitRuntime = False) to start debugging the package.

image

Make sure the package is selected en not the individual task (then the debugger also won’t stop).

Silverlight 3 How to resolve: Error Unknown element: OutOfBrowserSettings.WindowsSettings when enabeling out of browser mode

If you get the an error when enabeling out fo browser mode in Silverlight 3, this is because you’re enabeling it in the wrong way. Don’t use the AppManifest.xml but the project properties and check the “Enable running application out of the browser”. This will generate a OutOfBrowserSettings.xml file, like:

<OutOfBrowserSettings ShortName="TTS Toggle" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
  <OutOfBrowserSettings.Blurb>Download TTS Toggle</OutOfBrowserSettings.Blurb>
  <OutOfBrowserSettings.WindowSettings>
    <WindowSettings Title="TTS Toggle" />
  </OutOfBrowserSettings.WindowSettings>
  <OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>

 

image

 

Error: Unhandled Error in Silverlight Application
Code: 2007   
Category: ParserError      
Message: Unknown element: OutOfBrowserSettings.WindowsSettings.    
File:     
Line: 12    
Position: 44    

See: http://geekswithblogs.net/dlussier/archive/2009/09/17/134864.aspx

ReportViewer control does not show default images on IIS7

If you use the ReportViewer control in you’re C# web application and the ReportViewer does not show the default images (refresh button etc) then you can check you’re web.config if it contains the correct axd handler:

<add name=": Reserved-ReportViewerWebControl-axd" path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler" resourceType="Unspecified" preCondition="integratedMode" />

In mine web.config it look like:

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ScriptModule"/>
<remove name="UrlRoutingModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
  <add name=": Reserved-ReportViewerWebControl-axd" path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler" resourceType="Unspecified" preCondition="integratedMode" />
    <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>

How to sum TimeSpan in LINQ with C#

If you want to sum TimeSpan properties in LINQ with C#, use:

            List<TimeSpan> list = new List<TimeSpan>             {
new TimeSpan(1),
new TimeSpan(2),
new TimeSpan(3)
};
// TimeSpan.Zero is the initial offset, in this case 0 ticks
// subtotal is used to sum to items in the list
// t is the current item in the list
TimeSpan total = list.Aggregate(TimeSpan.Zero, (subtotal, t) => subtotal.Add(t));
Console.WriteLine(total.Ticks);
// Result: 6

 

 

Thanks to: http://stackoverflow.com/questions/970178/c-how-to-use-the-enumerable-aggregate-method

How to resolve on the HTC HD2: The device has either stopped responding or has been disconnected

If you copy a mp3 file to you’re HTC HD2 windows mobile device you can get the error: “The device has either stopped responding or has been disconnected”. This error occurred only when I connected my HTC HD2 with Active Sync. If you connect you’re HTC HD2 to you’re PC and choose “Disk Dive” in the Connect to PC screen on the HTC HD2, coping files won’t display the error and copying is much faster.

 image

image

How to start suspended MSDN subscription download with TransferMgr.exe

When you download software with you’re MSDN subscription account and suspend you’re download, you can resume the download by starting “C:\Windows\Downloaded Program Files\TransferMgr.exe” and press resume. I found the location of this executable by starting the taskmanager > right click “Microsoft File Transfer Manager” > Go To Process > right click “TransferMgr.exe” > Properties > The location shows the location of the executable.

image

image

 

image

SSIS 2008 Script Task using and reference a custom none GAC (not signed) assembly

 

If you reference an custom none GAC assembly from you’re SSIS 2008 script task, you can get an exception, stating the assembly could not be found.

Error

Error: 0x1 at Filesysteem opschoning: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.IO.FileNotFoundException: Could not load file or assembly ‘Ada.Cdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.
File name: ‘Ada.Cdf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’
   at ST_124cffcdeb3f407fa68f54b9192c0cdf.csproj.FileSystemCleaner.Clean()
   at ST_124cffcdeb3f407fa68f54b9192c0cdf.csproj.ScriptMain.Main()

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

   — End of inner exception stack trace —
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Task failed: Filesysteem opschoning
Warning: 0x80019002 at OpschoonProces: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
SSIS package "OpschoonProces.dtsx" finished: Failure.

 

Solution

To prevent this error, I use the AppDomain AssemblyResolve event to add a folder to the .NET assembly probing (search) path:

/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
namespace ST_124cffcdeb3f407fa68f54b9192c0cdf.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
/*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.
To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);
To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";
Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
To open Help, press F1.
*/
public void Main()
{
// Add bin folder to .NET assemlby search path
this.BindAssemblyResolveEventHandler();
FileSystemCleaner cleaner = new FileSystemCleaner();
cleaner.Clean();
Dts.TaskResult = (int)ScriptResults.Success;
}
/// <summary>
/// Add an evenhandler for adding a folder to the .NET assemlby search (probing) path.
/// </summary>
public void BindAssemblyResolveEventHandler()
{
var currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += LoadAssemlbyFromProductInstallationFolder;
}
/// <summary>
/// This function is called when the .NET runtime searches for an assemlby to load and can't find that assembly in the current search path.
/// The current search path includes "bin folder application", the global assemlby cache, system32 folder etc.
///
/// This function adds a folder to the current search path at runtime.
///
/// An assembly can be a dll or exe, the ResolveEventArgs argument does not cotain this information.
/// The code will first check if a dll exist in the given folder, if found it loads the dll.
/// If the dll is not found, the code checks if an executable exists in the given folder, if found it loads the exe.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
public Assembly LoadAssemlbyFromProductInstallationFolder(object sender, ResolveEventArgs args)
{
Assembly result = null;
if (args != null && !string.IsNullOrEmpty(args.Name))
{
var folderPath = GetExecutionPath();
var assemblyName = args.Name.Split(new string[] { "," }, StringSplitOptions.None)[0];
var assemblyExtension = "dll";
var assemblyPath = Path.Combine(folderPath, string.Format("{0}.{1}", assemblyName, assemblyExtension));
if (!File.Exists(assemblyPath))
{
assemblyExtension = "exe";
assemblyPath = Path.Combine(folderPath, string.Format("{0}.{1}", assemblyName, assemblyExtension));
}
result = Assembly.LoadFrom(assemblyPath);
}
return result;
}
/// <summary>
/// Get the current execution path
/// </summary>
/// <returns></returns>
public string GetExecutionPath()
{
return new Uri(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)).LocalPath;
}
}
}

Warning: 0x7 at : Cannot debug script tasks when running under the 64 bit version of the Integration Services runtime in a SSIS package

If you get a warning like:

Warning: 0x7 at Filesysteem opschoning: Cannot debug script tasks when running under the 64 bit version of the Integration Services runtime.

when trying to debug a SSIS package, change the project property [Run64BitRuntime] to False:

image