.comment-link {margin-left:.6em;}

kHSw

Friday, August 19, 2005

The given assembly name or codebase was invalid

Today we created a new project in Visual Studio .NET 2003, when we tried to run a webservice, we got this cryptic error message:

Server Error in 'TheProjectNameHasBeenRemoved' Application.
--------------------------------------------------------------------------------

Configuration Error
Description: An error occurred during the processing of a configuration file
required to service this request. Please review the specific error details
below and modify your configuration file appropriately.

Parser Error Message: The given assembly name or codebase,
'ThisNameHasBeenRemoved', was invalid.

Source Error:


Line 263: <add assembly="System.EnterpriseServices,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
Line 264: <add assembly="System.Web.Mobile,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
Line 265: <add assembly="*">
Line 266: </assemblies>
Line 267:


Source File:
c:\winnt\microsoft.net\framework\v1.1.4322\Config\machine.config Line:
265

Assembly Load Trace: The following information can be helpful to determine
why the assembly 'ThisNameHasBeenRemoved' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = ThisNameHasBeenRemoved
(Partial)
LOG: Appbase =
file:///c:/inetpub/wwwroot/TheProjectNameHasBeenRemoved/ThisNameHasBeenRemoved
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
===

LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Post-policy reference: ThisNameHasBeenRemoved
LOG: Attempting download of new URL
file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET
Files/ThisProjectNameHasBeenRemoved/5a38ff29/c803bfd4/ThisNameHasBeenRemoved.DLL.
LOG: Attempting download of new URL
file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET
Files/ThisProjectNameHasBeenRemoved/5a38ff29/c803bfd4/ThisProjectNameHasBeenRemoved/ThisNameHasBeenRemoved.DLL.
LOG: Attempting download of new URL
file:///c:/inetpub/wwwroot/ThisProjectNameHasBeenRemoved/bin/ThisNameHasBeenRemoved.DLL.
LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Post-policy reference: ThisNameHasBeenRemoved,
Version=1.0.2057.22204, Culture=neutral, PublicKeyToken=null

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032


What was causing this error?
If you run as ASP.NET website or webservice, files are copied to the Temporary ASP.NET Files folder.
The full path looks like this:
C:\Windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\<Virtual Application Folder>\6ca4fcfa\e8f0a674\assembly\dl2\e377cdc3\f1962fd2_31a3c501\<Assembly Name>.DLL

We had chosen a very descriptive name for our assembly causing the length of the total path mentioned above to exceed the 256 character limit... So the assembly could not be copied to the temporary folder. It's amazing this limit still counts for modern applications...

In Visual Studio .NET 2005 there are checks on the length, you'll even get a decent message if a path is too long! (At least in Beta 2)

Wednesday, August 03, 2005

Copy a file with progressbar in VB.NET

Today I wanted to create a control that could copy files in VB.NET with some progress indication. I did some searches on the Internet and managed to build a working control. However, I would like to share the basics with all of you...

First declare some API functions:

Private Delegate Function CopyProgressRoutine(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32

Private Declare Auto Function CopyFileEx Lib "kernel32.dll" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As CopyProgressRoutine, ByVal lpData As Int32, ByVal lpBool As Int32, ByVal dwCopyFlags As Int32) As Int32

Add a button (Button1) to your form and add this code to the Click event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cpr As New CopyProgressRoutine(AddressOf CopyProgress)
CopyFileEx("C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll", "C:\dao360_delete.dll", cpr, 0, 0, 0)
End Sub

Make sure the file exists on your filesystem, I advise you to take a big file (> 100MB) to see the progressbar working...

Add a ProgressBar (ProgressBar1) to your form and create a function called CopyProgress:

Private Function CopyProgress(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
ProgressBar1.Value = Convert.ToInt32(TotalBytesTransferred / TotalFileSize * 100)
End Function

Click the button and watch the spectacle ;-)


CopyFileEx will return a nonzero value in case of success, it will return 0 in case of error. Use this code to retrieve the error information:
Dim copyError As Exception = New System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error)

If you want to cancel the copy process and delete the new file, make sure CopyProgress returns PROGRESS_CANCEL
Private Const PROGRESS_CANCEL As Integer = 1

This function will overwrite an existing file by default. If you don't want this to happen, change the function call to
Private Const COPY_FILE_FAIL_IF_EXISTS As Integer = 1
CopyFileEx("C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll", "C:\dao360_delete.dll", cpr, 0, 0, COPY_FILE_FAIL_IF_EXISTS)

Copying will fail if the file has the Hidden or the Readonly attribute. Use this code to reset the attributes to Normal:
Dim fi As New System.IO.FileInfo(destinationFileName)
If fi.Exists Then
fi.Attributes = IO.FileAttributes.Normal
End If


 
Stefanie Worm is het liefste vrouwtje van de wereld.
Melina is de liefste schatsie van de wereld (Erik De Maeyer).