.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Unable to unload new appdomain completly

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :Windows Application

Hello friends,

I am using VS2008 with C#. I have an issue related to reflection. In my application I have a dropdown with 2 options. if user selects option1 assembly1 is loaded and invoke a method of loaded assembly. If the user selects option2, assembly2 gets loaded and a method of loaded assembly is invoked. now the issue is both the assemblies have most of the classes common. When the user selects option1 assembly1 loads and invoke a method. this method sets some static object. Now when user selects option2 it loads assembly2 and when that method is invoked it throws an exception due to the static method. I am not suppos to change the code of the assembly namespace. So the solution should be that the assembly should be unloaded after the method has been invoked. But it is impossible to unload an assembly once loaded.

My Findings. By searching on the net what I have learned is I have only one option that create a new appdomain and load the assembly in that appdomain and after the method invoke unload the assembly. i have implemented that but still I am getting the same issue. My guess is that I am not properly unloading the appdomain. i am writing  down the code that I am using. Please have a look and let me know if I am making any mistake while operating with appdomains.

AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;


View Complete Post

More Related Resource Links

AppDomain.Unload effects Unable to evaluate expression because the code is optimized or a native fra

Hello, I create a custom AppDomain.Create().  I registered the Unhandled Exception Event from my custom AppDomain. In the Unhandled Exception Event i try to Unload my AppDomain with AppDomain.Unload. But this effects a "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." Have anyone a idea what i can do against this behaviour. greetints

AppDomain Unload does corrupt Thread Pool

Hi,I was just trying to run a simple scenario:1. Create AppDomain2. Use up all Worker threads from Thread Pool 3. Unload AppDomain before the worker threads have finished.4. Try to queue another WorkItem in your default or some other AppDomainResult: The .NET thread pool is dead because there are no threads left for the other AppDomain. ThreadPool Threads are not given back to the thread pool when an AppDomain.Unload is performed. I think it is ok to not kill the threads (reliability) but what is not ok is that there are no threads left for other AppDomains. An AppDomain unload should increase the number of worker/io completion port threads which are currently running inside the to be unloaded AppDomain to ensure that you do not run out of threads after 2-3 days of regular operation when some AppDomains where created and destroyed in the meantime.This will eat up your thread pool quite fast.Sample Code to reproduce:using System;using System.Collections.Generic;using System.Text;using System.Threading;using System.Diagnostics;namespace ThreadPoolAndAppDomain{    [Serializable]    public class Worker    {       public Worker()       {}       int nQueuedItems = 0;              public void QueueWorkItems(int n)       {           for (int i = 0; i < n; i++)           {               ThreadPool.QueueUserWorkItem(delegate(object state)               {                   lock (this) 

Unable to load Reg-Free COM dll reference in AppDomain

Retrieving the COM class factory for component with CLSID {E1B87327-4DB5-492E-8AC2-F542BCA3C912} failed due to the following error: 80040154. I have a .net dll refering Reg-Free COM DLL, when try to load my .net dll in AppDomain i get above error. If i regster it works fine. Also it works fine if i refer my .net dll from stand alond exe(works fine in both COM register and un-register scenarios). AppDomain is not recongnising Reg-Free COM dll.ravi kumar reddy

Assembly is not unloaded on AppDomain unload


In order to attempt to unload an assembly I use the following code. Yet the assembly is not unloaded. The second call to Execute is performed yet it shouldn't be available anymore should it?

Also the HandlerOne.dll is still locked. As I load it from memory I wonder why it is still locked


    // Copy assembly in memory to prevent file lock
    System.IO.StreamReader reader;
    byte[] buf;
    using ( reader = new System.IO.StreamReader( "HandlerOne.dll", System.Text.Encoding.GetEncoding( 1252 ), false ) )
      buf = new byte[reader.BaseStream.Length];
      reader.BaseStream.Read( buf, 0, System.Convert.ToInt32( reader.BaseStream.Length ) );

    // Create a seperate AppDomain
    // Load the handler
    AppDomain d = AppDomain.CreateDomain( "one" );
    Assembly a = d.Load( buf );
    Type typ = a.GetType( "HandlerLib.HandlerOne", <

AppDomain.Unload called multiple times?




     In a simple console app, I created a separate AppDomain (name: ad2)  to do some work.  In this AppDomain, I created a separate worker thread  and deliberately put the thread to sleep for long time (2 mins) in the Finally block.


      I also subscribed to the ad2’s Unload event  to do some logging.


      Immediately after calling the worker method, I called the AppDomain.Unload(ad2) in the main thread.  Because of the long Thread.Sleep() in the worker thread finally block, a CannotUnloadAppdomainException was thrown when calling AppDomain.Unload(ad2).

Textbox in ItemTemplate inside Gridview, unable to get the value


Hi. I have a itemtemplate inside a gridview.

<asp:TemplateField HeaderText="Enter OTP">
                            <asp:Label ID="Label2" runat="server"
                                style="font-family: Arial, Helvetica, sans-serif; font-size: x-small"
                                Text="PIN Num:"></asp:Label>
                            &nbsp;<asp:TextBox ID="txtPIN" runat="server" Height="21px" Width="100px"></asp:TextBox>

Failed to create AppDomain


Recently updated my system to use Visual Studio 2010, and projects will no longer compile. All of them give the error "Failed to create AppDomain." Intellisense does not work either (except for standard HTML tags), and individual pages will also not compile.

Points of note:

  • All sites are hosted on UNC shares (although it doesn't work on a new site created on local drive either)
  • Language is mostly C#
  • No explicit code is creating AppDomain objects
  • Sites compiled fine under both VS 2005 and 2008 both before and after VS 2010 installation
  • Sites compile and run fine from the IIS server on the remote machines (one IIS 6, one IIS 7)

Things I've tried (some obviously shouldn't have any bearing on it, but I've tried just about everything that anyone suggested on any forum I could find, most of which seemed to apply to IIS, not VS):

  • renaming/deleting security.config
  • running caspol -reset
  • re-registering asp.net: aspnet_regiis.exe -ua / aspnet_regiis.exe -i
  • removing VS 2005, 2008, 2010, and then re-installing just VS 2010
  • adding the UNC path to the local intranet zone (internet options control panel)
  • adding the UNC path to LocalIntranet_Zone in the ASP.Net 2.0 control panel (runtime security policy/machine/al

Unable to make connection to database?


Hy guys. I try to connect my database for so long so i wrote two type of codes. Let's discuse first on.

I have database called PhoneDirectory.

It have only one table named Residents.

I have button wiht ID="Button1".

I want when i click this button to see all of my residents. 

I want to see the result in DetailsView and to be able to edin, delete and add new resident.

First try with SqlDataSource so i wrote this:

<asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>" 
              SelectCommand = "SELECT * FROM Resident "

Unable to get all the values from a field


Am reading an XML from web service and storing in  a dataset. 
then in write to a DataTable as follows

 DataTable dtResult1 = dsSearch.Tables["RESULTSET"];    
 DataTable dtHIT = dsSearch.Tables["HIT"];     
 DataTable dtField = dsSearch.Tables["FIELD"]; 

The issue  is  in the DataTable dtField i can only see 3 columns FieldID,Name,HIT_ID

The corresponding values in the dataTable looks like this for the corresponding fileds


I am unable to get the Field Name values 1,8799f4646b6ed9acde142581a84f75a6 ,234B5F5F-F247-4EB6-9E39-A7B64C7FE1BD,Yes...etc

What would be the cause for this...Any Help

Below is the structure of the XML-

- <HIT NO="1" RANK="2955" SITEID="0" MOREHITS="0" FCOCOUNT="0"> 
<FIELD NAME="rank">1</FIELD> 
<FIELD NAME="internalid">8799f4646b6ed9acde142581a84f75a6 </FIELD> 
<FIELD NAME="contentid">234B5F5F-F247-4EB6-9E39-A7B64C7FE1BD</FIELD> 
<FIELD NAME="contentids" /> 
<FIELD NAME="collection&

unable to access control inside webuser control



I have used calender web user control inside my project where i took textbox,button and calender.....but after dragging onto my aspx page....i am unable to access this textbox,calender and button on aspx page...Pls help me to find out the solution.

Unable to cast object of type 'System.Web.Mvc.ValueProviderResult' to type 'System.IConvertible'


 Why am I getting this error on line:

               sp.Price = Convert.ToDecimal(collection.GetValue("Price"));

sp is :
  SPecials_Templates sp = new SPecials_Templates();

SPecials_Templates Defined:

    public partial class SPecials_Templates
        public class SPecials_TemplatesMetaData

            public object Key { get; set; }
            public object Template_Name { get; set; }
            public object Headline { get; set; }

unable to attach database, security setting?


Hi folks,

I am using VS 2010 Professional with SQL Server 2008 Developer.  I right click on the App_Data folder in solution explorer and add an existing item, then navigate to the correct database.  However, I receive a pop up that Access is Denied.  How do I fix this? 

unable to connect to database



I am using visual studio 2005 and sql server 2005.

I am developing a small quiz application and i have stored the connection string in app.config file which is given below.:

<?xml version="1.0" encoding="utf-8" ?>
        <add name="quizdb"
            connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Quiz Application.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            providerName="System.Data.SqlClient" />
i have retrieved connection string property through configurationmanager class 

and when i m connecting to database  it gives me a runtime error:


Sql Exception was unhandled

System.Data.SqlClient.SqlException was unhandled
  Message="An attempt to attach an auto-named database for file F:\\Quiz\\Quiz\\bin\\Debug\\Quiz Application.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located

Unable to select any stored procedure while creating TableAdapters in wizard


I'm using VS 2008 and SQL 2008.

I have created the tables and the stored procedures in SQL 2008.

In VS 2008, I created DataSet1.xsd in App_Code and created the connectionString in web.config file.

Then when I go into the DataSet1.xsd and try to add a TableAdapter, strange things happened.

First I chose the data connection, then selected "Use existing stored procedure", then there was nothing listed in the dropdownlists (in Select, Insert, Update, or Delete). 

I'm sure the connectionString is correct because if I choose "Use SQL statement" and type in a "select * from mytable1", the TableAdapter can be created without any problem.

Any suggestions?

Unable to move Wiki pages with Bracketed ([[, ]]) Links


I'm using Microsoft Office Sharepoint Server 2007 (pre-SP1) to host a Wiki, and it's been a learning process as I've been going along.  In this process, I keep finding better places to keep Wiki Pages and Wiki Libraries, so I move things around to find the best fit.  I've run into a strange problem while moving my collection of ~100 Wiki pages, and I'm curious to see if others have it to.  The problem is, I cannot move or copy Wiki Pages that contain links to other Wiki pages using the bracket method (of writing a link as [[other page]]).

Here's how I reach the problem:

-Create 2 Wiki Pages Libraries,  I called mine Wiki PagesA and Wiki PagesB
-I go into my Wiki PagesA library and create a new Wiki page.
-I call it "linktohome" and enter only a single line in the body, "[[home]]"
-I can open it up and it works just fine and the link redirects me to the Home page in the local Wiki PagesA library so it's all good.
-Next in my main Site Collection that's hosting these libraries, I'll pull down Site Actions and go into Manage Content and Structure.
-I can browse into Wiki PagesA and the linktohome document appears
-But, when I try to copy (or move) linktohome to Wiki PagesB library I get an error that says:

Unable to copy/move wiki pages with links to other wiki pages

When I try to copy or move wiki pages from one 'Wiki library A' to 'Wiki library B' through 'content and structure', I get an error for the pages which contain links to other wiki pages, does sameone has a clue how to fix this:

<error><message>Het item bestaat niet. Mogelijk is het door een andere gebruiker verwijderd.</message><full>Microsoft.SharePoint.SPException: Het item bestaat niet. Mogelijk is het door een andere gebruiker verwijderd. ---&gt; Microsoft.SharePoint.SPException: Het item bestaat niet. Mogelijk is het door een andere gebruiker verwijderd. at Microsoft.SharePoint.SPListItem.EnsureItemIsValid() at Microsoft.SharePoint.SPListItem.PrepareItemForUpdate(Guid newGuidOnAdd, Boolean bMigration, Boolean&amp; bAdd, Boolean&amp; bPublish, Object&amp; objAttachmentNames, Object&amp; objAttachmentContents, Int32&amp; parentFolderId) at Microsoft.SharePoint.Deployment.ListItemSerializer.AddOrUpdateDoclibItem(SerializationInfoHelper infoHelper, SPListItem&amp; listItem, SPWeb web, Guid newId, String&amp; listItemServerRelativeUrl, Boolean bIsPublish, Boolean exists, StreamingContext context, ISurrogateSelector selector, ImportObjectManager objectManager) at Microsoft.SharePoint.Deployment.ListItemSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurr

Unable to open pdf from document library MOSS 2007


When I click on a pdf document uploaded in a document library it comes up with a blank page. 

I guess it's trying to open pdf on the browser. I turned off "Display PDF in browser " option in Adobe Preferences, but it doesn't help, same issue.

I tried other browsers too, it's the same issue.

I am able to open all other pdf files local to my machine fine.

I am using IE 8 on my machine (Windows 7) and the Sharepoint server is MOSS 2007.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend