Hello,
(sorry for reposting this.)
We are having the following scenario:
A ASP.NET Application (C#) is using a managed C++ assembly, which is a
thin wrapper around an old C++ lib.
(We are using .NET framework 1.1)
In the managed C++ assembly there are some managed (gc) and some
unmanaged (nogc) classes. There is one unmanaged class (a singleton),
which has a reference (gcroot/GCHandle) to a System.Collecti ons.Hashtable.
So the callgraph is something like this: .NET --> C++ --> .NET
Everything works fine, until ASP.NET decides to unload and reload the
AppDomain. (e.g. touching the web.config/machine.config) .
If now a call is made to the component, it crashes at the point, where
the referenced Hashtable (GCHandle) is used.
I saw a few articles about this problem, including a bug report in msdn
( http://support.microsoft.com/default...;EN-US;309694).
The bug report applies to .NET framework 1.0, so I'm wondering, if this
bug still exists in 1.1?
Is this a known bug in 1.1 too? Will the next version of the framework
fix this?
Are there any other workarounds beside the solutions in 309694.
Thanks in advance,
Hans-Jürgen. 5 2714
Hi Hans,
As for the problem you mentioned, do you means that currently if we call
that MC++ component after the asp.net appdomain unload and reload, the
application will crash?
As for the kb article you mentioned, I'll consult some further experts to
confirm this and I think we can do some further tests currrently:
Try creating another simple MC++ assemlby( reference a unamaged dll, but
don't be too complex) and use it in the asp.net web application and do the
same test to see whether the problem reoccur. That'll help confirm whehter
the problem is only specified to the particular Mc++ component.
I'll update you about the kb article's info as soon as possible, and if you
have any other findings , please also feel free to post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hello,
I can reproduce the error in a simple example.
I think the problem is, that the singleton (static variable) in the
managed c++ assembly is not notified of the AppDomain unloading.
So it creates a reference (gcroot) to a managed object in the first
AppDomain and after unloading the AppDomain the reference is invalid.
(->crash).
By the way, there is another question concerning managed c++ Dlls.
The documentation recommends not to implement a Dll-Entry point.
Having static instances of unmanaged classes requires to call
the CRT-initialization. The recommended way is to call
__crt_dll_initi alize and __crt_dll_termi nate at initialization time (but
not from within Dll-Entry point).
How should I do this in an ASP.NET environment. The methods
Application_Sta rt/Application_End (global.asax) are called more then
once. Every time I touch web.config/machine.config these methods are
called. But the managec c++ dll is loaded just once.
Is it allowed to call __crt_dll_initi alize and __crt_dll_termi nate more
than once?
What is the recommended point in ASP.NET application to initialize
managed c++ Dlls?
The article I read: http://support.microsoft.com/default...&product=vcNET
Thanks in advance,
Hans-Jürgen.
Steven Cheng[MSFT] wrote: Hi Hans,
As for the problem you mentioned, do you means that currently if we call that MC++ component after the asp.net appdomain unload and reload, the application will crash?
As for the kb article you mentioned, I'll consult some further experts to confirm this and I think we can do some further tests currrently:
Try creating another simple MC++ assemlby( reference a unamaged dll, but don't be too complex) and use it in the asp.net web application and do the same test to see whether the problem reoccur. That'll help confirm whehter the problem is only specified to the particular Mc++ component.
I'll update you about the kb article's info as soon as possible, and if you have any other findings , please also feel free to post here. Thanks.
Regards,
Steven Cheng Microsoft Online Support
Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Hi Hans,
Thanks for the followup. Yes, I think your thought on the app crash is
reasonable. If so, is it ok that we provide some protected code to catch
such exception and reinitialize the static reference when it is called
after the application reloaded.
Also, as for the further question you mentioned, I'll do some furthe
research and will update you as soon as I got any information. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hello Steven,
What do you mean by "provide some protected code" ?
Do you mean in the next Version of the runtime or some code in my
managed c++ assembly.
Thanks for your help,
Hans-Jürgen
Steven Cheng[MSFT] wrote: Hi Hans,
Thanks for the followup. Yes, I think your thought on the app crash is reasonable. If so, is it ok that we provide some protected code to catch such exception and reinitialize the static reference when it is called after the application reloaded.
Also, as for the further question you mentioned, I'll do some furthe research and will update you as soon as I got any information. Thanks.
Regards,
Steven Cheng Microsoft Online Support
Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
Hi Hans,
Thanks for the followup. The protected code I mentioned means some thing in
our own code ( in that mc++ assmelby).
Also, I've got some suggestions from some other experts, here are their
original description regarding on your two question:
=============== ===========
For the first issue, this should be fixed in 2003. The issue was with the
inability to retain the appdomain for virtual function calls across a
transition boundary. In 2003, VC++ and the CLR implemented support to
retain the originating appdomain across the transition boundary. You will
need to rebuild everything C++ that you built with /clr with the 2003
compiler and then use the 2003 CLR to get the fix.
For the second issue, it is safe to call __crt_dll_initi alize/terminate
multiple times. You definitely do not want to call either of these
functions while you thread has obtained the loader lock. One such occasion
is during a call to a DllMain (or something that DllMain calls such as
global object constructors).
=============== =============
Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: BillyO |
last post by:
In the attached code fragment I have a buffer overflow and
a memory access violation. When I run the code .Net fails to
verify the IL because of the buffer overflow and I get an exception
as expected. My question relates to the memory access violation,
specfically, what should happen? My guess is that since the good
ole new operator allocates the memory we get an SEH memory access
violation exception. Given that this can occur in my...
|
by: Francis Tsui |
last post by:
We have a COM object implemented using managed C++. When the COM object is
loaded from unmanaged code it works fines. However when we try to use the
managed COM object through some unmanged code and COM interop from ASP.Net,
we often get a DllNotFound Exception. I've read about some problem with
managed COM objects causing problems if AppDomains get unloaded. Does
anyone know what the rules are for accessing managed COM objects in...
|
by: cameron |
last post by:
I have a page that needs to process aproximately 7000 LDAP entries and
does 10-12 SQL DB calls per entry. It is a busy, busy page. I have it
schedualed to run every night at 4 am server time. It runs for about 2
hours, processing a smidge over 4000 of the entries and then borks with
the error:
: Attempted to access an unloaded AppDomain.
The IIS logs shows a status of 200 for that page, the Event Viewer shows
nothing unusual around...
|
by: Charles Herring |
last post by:
In my asp.net application I upload a video file and then need to get the
duration and other properties.
I get "Attempted to access an unloaded AppDomain" when I instanciate the
Video object.
I am impersonating Administrator.
Here is the code:
Dim v As Video = New Video(fname, True)
intHeight = v.DefaultSize.Height
|
by: news |
last post by:
Hello,
We are having the following scenario:
A ASP.NET Application (C#) is using a managed C++ assembly, which is a thin
wrapper around an old C++ lib.
(We are using .NET framework 1.1)
In the managed C++ assembly there are some managed (gc) and some unmanaged
(nogc) classes. There is one unmanaged class (a singleton), which has a
| |
by: jake |
last post by:
I've seen many articles that claim the files in the App_Code directory are
treated in the same way as aspx-files in ASP 1.1. Well, this does not seem to
be the case, at least in Web Developer 2005 Express Beta2. If I change
anything in any of the class files residing in App_Code, the AppDomain is
unloaded and all application data, including all sessions, is lost. Is there
anything I can do to prevent this?
This undesired side-effect...
|
by: Basti |
last post by:
Hello,
I'm working with .Net 2.0. I tried to get attributes of an unloaded
assembly. So, the sole way I know is to create a new child application
domain, in this app domain I load the assembly, read out the
attributes, and unload the child app domain. But in this moment, I load
the assembly into the child app domain, the assembly occurs in the
parent app domain, too. And after unloading the child app domain the
assembly is still loaded in...
|
by: draskin |
last post by:
Hello,
We have a situation where a managed C++ assembly links with native C++ dll.
There is a callback mechanism which calls back into the managed code
asynchronously. Since native classes cannot hold onto a managed reference,
we need to have a managed static member which we access during the callback
and then get into the managed code.
This works great in a console or WinForm app. But in ASP.NET it doesn't. The
reason is that each...
|
by: Dave Burns |
last post by:
Hello,
We have a situation where a managed C++ assembly links with native C++ dll.
There is a callback mechanism which calls back into the managed code
asynchronously. Since native classes cannot hold onto a managed reference,
we need to have a managed static member which we access during the callback
and then get into the managed code.
This works great in a console or WinForm app. But in ASP.NET it doesn't. The
reason is that each...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |