473,698 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access violation in MSCORWKS.DLL

I have created an event sink in my ATL COM project. The event sink receives
events from a C# component. There is no problem with receiving events but
when my COM object is released I get an access violation - (MSCORWKS.DLL):
0xC0000005: Access Violation.

At first I thought it could be due to my C++ code but after quite a lot of
investigation I don't think there is nothing wrong with it. The access
violation occurs after the destructor of my COM object. It seems to be
coming
from the .NET garbage collector. Could it be that the GC is trying to
delete memory twice? How do I fix this problem? The events are being sent
from the TransferModule.

I'm very new to C#. Should I implment a dispose method?

Here's the code for my Transfer Module:

using System;
using System.Runtime. InteropServices ;
using ATWSConsumer.Tr ansferServer;
using System.IO;
using System.Windows. Forms;

namespace ATWSConsumer
{
public delegate void UpdateDelegate( int percentage);

[Guid("2278B7FD-3DD8-42cc-93D7-824C2FB32EA9")]
public interface ITransferModule
{
int TransferBlockSi ze {get; set;}
ConnectionModul e Connection {get; set;}

bool Discover();
}

[Guid("2E638A47-161F-4b6c-9BBC-AD4AC2EC53FA"),
InterfaceType(C omInterfaceType .InterfaceIsIDi spatch)]
public interface ITransferModule Event
{
[DispId(1)] void UpdateProgress( int percentage);
}

[Guid("40A69B6B-7F46-4929-BEA5-CFCBB45D5443"),
ClassInterface( ClassInterfaceT ype.None),
ComSourceInterf aces(typeof(ITr ansferModuleEve nt))]
public class TransferModule : ITransferModule
{
public event UpdateDelegate UpdateProgress;

public ConnectionModul e m_oConnection;
public string m_sError;
public int m_nTBSize;

public ConnectionModul e Connection
{
get{return m_oConnection;} set{m_oConnecti on = value;}
}

public string GetLastError()
{
return m_sError;
}

public int TransferBlockSi ze
{
get {return m_nTBSize;} set {m_nTBSize = value;}
}

private TransferService GetTransferServ ice()
{
if ( m_oConnection == null || m_oConnection.m _serviceCache == null )
return null;
ServiceInfo si = m_oConnection.m _serviceCache.G etServiceByType
(ServiceInfo.Se rviceType.Trans ferService);

if (si == null)
{
m_oConnection.S etErrorString
(m_oConnection. m_serviceCache. GetLastError()) ;
return null;
}

TransferService transferService = new TransferService ();
transferService .Credentials =
System.Net.Cred entialCache.Def aultCredentials ; // to resolve security
problems with ASP by Yuriy E. Zatuchnyy at 23 Sep 2004
transferService .Url = si.m_sServiceAd dress;

return transferService ;
}

public TransferModule( )
{
// default transfer block size (4k)
m_nTBSize = 4096;
}

public TransferModule( ConnectionModul e connectionModul e)
{
m_oConnection = connectionModul e;
// default transfer block size (4k)
m_nTBSize = 4096;
}

public bool Discover()
{
TransferService transferService = GetTransferServ ice();
if (transferServic e == null)
return false;

return true;
}

public string UploadFile(stri ng sFilePath)
{
int nBytesRead = 0;
byte[] byteBuffer;
string sUploadToken = "";
FileStream fileStream = null;
long lTotalBytesRead = 0;

TransferService transferService = GetTransferServ ice();
if (transferServic e==null)
return "";

// get the upload token to allow an upload
WSResult wsResult = transferService .RequestUploadT oken
(/*m_oConnection. m_strSessionKey ,*/0); // by Yuriy E. Zatuchnyy at 28 July
2004
if (!wsResult.Succ ess)
{
m_sError = wsResult.Descri ption.InnerText ;
return "";
}

sUploadToken = wsResult.Descri ption.InnerText ;

try
{
fileStream = new FileStream (sFilePath, FileMode.Open,
FileAccess.Read , FileShare.ReadW rite);
}
catch (Exception E)
{
m_sError = E.Message;
CleanupUpload(s UploadToken);
return "";
}

long lFileSize = fileStream.Leng th;
byteBuffer = new byte[m_nTBSize];
nBytesRead = fileStream.Read (byteBuffer,0,m _nTBSize);
while (nBytesRead > 0)
{
wsResult = transferService .Upload
(sUploadToken,n BytesRead,byteB uffer);
if (!wsResult.Succ ess)
{
m_sError = wsResult.Descri ption.InnerText ;
fileStream.Clos e ();
CleanupUpload(s UploadToken);

return "";
}
lTotalBytesRead += nBytesRead;
if (UpdateProgress !=null)
{
UpdateProgress( (int)((lTotalBy tesRead * 100) / lFileSize));
}
nBytesRead = fileStream.Read (byteBuffer,0,m _nTBSize);
}

fileStream.Clos e ();
return sUploadToken;
}

public bool CleanupUpload(s tring sToken)
{
TransferService transferService = GetTransferServ ice();
if (transferServic e == null)
return false;

WSResult wsResult = transferService .UploadComplete (sToken);

if (!wsResult.Succ ess)
{
m_sError = wsResult.Descri ption.InnerText ;
return false;
}

return true;
}

public bool DownloadFile(st ring sFileLocation, string sToken, long
lFileSize)
{
long lChunkNumber = 0;
long lBytesReceived = 0;
FileStream fileStream = null;
TransferService transferService = GetTransferServ ice();
if (transferServic e == null)
return false;

try
{
fileStream = new FileStream (sFileLocation, FileMode.Create );
}
catch (Exception E)
{
m_sError = E.Message;
return false;
}

TransferServer. BinaryResult binResult =
transferService .Download(sToke n, lChunkNumber++, m_nTBSize);
while (binResult.lByt esRead > 0)
{
if (!binResult.Suc cess)
{
m_sError = binResult.Descr iption.InnerTex t;
fileStream.Clos e ();
return false;
}
lBytesReceived += binResult.lByte sRead;
if (UpdateProgress !=null)
{
UpdateProgress( (int)((lBytesRe ceived * 100) / lFileSize));
}
fileStream.Writ e (binResult.Cont ent,0,(int)binR esult.lBytesRea d);
binResult = transferService .Download(sToke n, lChunkNumber++,
m_nTBSize);
}

fileStream.Clos e ();

return true;
}
}
}
Nov 17 '05 #1
0 1840

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2720
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access violations aren't part of the standard C++ >> exception handling support. On Windows, a particular MSVC compiler >> option enables Microsoft's Structured Exception Handling (SEH) in C++ >> EH so that a catch (...) will catch an access violation. ...
2
2531
by: tony | last post by:
(5b4.f74): Access violation - code c0000005 (!!! second chance !!!) eax=00800000 ebx=77e760cb ecx=00a3dc1c edx=00000004 esi=80000016 edi=000000c8 eip=792cfcbb esp=0e47f91c ebp=0e47f928 iopl=0 nv up ei pl nz na po nc cs=001b ss=0023 ds=0023 es=0023 fs=0038 gs=0000 efl=00000206 mscorwks!gc_heap::c_promote_callback+0xfe: 792cfcbb 8b3c81 mov edi, ds:0023:02a3dc1c=????????
0
1811
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a TabControl to my form and placed a
8
15297
by: Gary Joy | last post by:
I really am banging my head with this one... I have a regular unmanaged C++ application that is using mixed DLLs to (amongst other things) call a C# back-end (which is using ADO .NET). I am getting random crashes, typically after 15-60 minutes of inactivity. The error message and call stack are listed below. Unhandled exception at 0x792483e0 (mscorwks.dll) in debug_build_wks_crash.dmp: 0xC0000005: Access violation reading location...
1
2257
by: tony | last post by:
hi. my NET application is using mixed c++ dll ( managed and unmanaged) in that dll , im calling api's of unamanged dll. my application crash with no exception or warning. its hard to find when the crash happen ,and where.
0
1127
by: techie | last post by:
Hi, I've created a COM object in VC++ that I call from XMetal. I pass the COM object (via a XMetal macro) my XMetal Application object by a put_ method. In my put_ method I call QueryInterface for the _Application interface and create an instance of a class called CXMetalApp: STDMETHODIMP CXMLEditorInterface::put_Application(LPDISPATCH newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState())
0
1394
by: techie | last post by:
I have created an event sink in my ATL COM project. The event sink receives events from a C# component. There is no problem with receving events but when my COM object is released I get an access violation - (MSCORWKS.DLL): 0xC0000005: Access Violation. Here's my event sink class: namespace { static const int EVENT_ID = 111;//any arbitary value
2
4281
by: =?Utf-8?B?c29jYXRvYQ==?= | last post by:
Hi, I have a DLL in VC6, when a specific function is called it will spawns a few threads and then return. The threads stay running and inside one of these threads an event is created using the win32 CreateEvent() call: Code Snippet static HANDLE hReadyEvent;
39
4272
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it just now, I am getting the subject error message (specifically: PHP has encountered an access violation at 00F76E21). The error is NOT occurring on every page request (but it is on most of them) and, when I get the error, simply pressing <F5to...
0
8676
marktang
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...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
jinu1996
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...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7732
agi2029
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...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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();...
0
4370
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.