|
Hey everyone,
I need a way to look at a compiled assembly and determine what variable types are allocated during a method call. Is there a way to do this in .NET, possibly using reflection? I've got an enterprise level application that uses a number of objects that implement IDisposable. Some of the coders have not been disposing of these objects when they are finished with them. I need some way to track down the methods where this is occurring. Any ideas?
Will
|
|
|
|
|
Look here: http://www.aisto.com/roeder/dotnet/[^]
It is just the best "reflecting" and decompiler program - a must-have!
You can explore the code and resources of any assembly in (almost) every .net language you want!
|
|
|
|
|
I hope this question don't win "The Most Stupid Question Of The Day" prize,
but I was just wondering if there is an easy way to import the macros from some
C header files (like CommCtrl.h) in C#. Cause they're very handy and the WinForms
controls don't provide all of the functionality of the Windows Shell controlls.
|
|
|
|
|
|
C# doesn't support header files and there is no utility to "import" them from other languages. You'll have to recode, by hand, what you want out of the header into C# code and make sure it ends up in an appropriate place in your code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
OK, thanks for both replies.
The hidden idea in the question was also to find someone
that has already done that
|
|
|
|
|
The problem with writing a translator for this is it has no clue in what context translated code should be in and, therefore, can't predict where the new code should go.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Ok for a while now ive have been tring to save an object from my resources as a file on the hard drive. The object is a byte[]. You may have seen questions regarding this.
Recently i have tried to get it into a stream and then save the stream. But i had problems getting it into a stream, i got alot of help for this and am grateful, but after trying:
FileStream fs = rm.GetObject("outside") as FileStream;
I got rid of the error "specified cast is not valid", and obtained a new one "object reference not set to an instance of the object". In other words, the filestream (fs) is still null, even after making it equal my object.
Any ideas, help, large mallets... would be GREATLY GREATLY apreciated.
I have beem trying to get this to work for a total of about 10 hours over the past month, but i realy need to get this sorted soon.
If you have any ideas on how to save the object without getting it into a stream post them as well.
Thanks in advance for putting up with me!
|
|
|
|
|
OK, as I understand, you have a byte array (the bunary representation of some file) in
memory and you want to flush it to the disk. If that's the situation, I think I can help.
I recently wrote a similar class. Here's the SaveAs method:
_bytes is a byte[] array - a private class field.
<code>public void SaveAs(string filePath)
{
using(FileStream stream = System.IO.File.OpenWrite(filePath))
{
stream.Write(_bytes, 0, _bytes.Length);
}
}</code>
|
|
|
|
|
If rm.GetObject("outside") returns a byte[], then how do you expect to cast it to a FileStream. The 'as' operator casts an object if possible and returns null if it can't. The objects cannot be directly converted into each other therefore, fs is null.
The easiest stream you can create with a byte[] array is MemoryStream.
MemoryStream ms = new MemoryStream((byte[])rm.GetObject("outside"));
If your goal is to write a byte[] array to a file then try a pattern like this:
byte[] tmp = (byte[])rm.GetObject("outside");
FileStream fs = new FileStream(FILE_NAME, FileMode.CreateNew);
fs.Write(tmp,0,tmp.Length);
fs.Close();
|
|
|
|
|
hi,
im trying to get a http site using httprequest. the problem ist, whenever a site contains frames i get only one frame, not the whole site. what can i do?
this is part of my code:
string getSite(String url, String referer) {<br />
try<br />
{<br />
if (url.StartsWith("www")) {url="http://"+url;}<br />
CookieContainer CookieCont = new CookieContainer();<br />
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(url);<br />
if(this.boxUseProxy.Checked)<br />
{<br />
WebProxy proxyObject = new WebProxy(this.boxProxyHostname.Text.Trim());<br />
proxyObject.Credentials = new NetworkCredential(this.boxProxyUsername.ToString(), this.boxProxyPasswort.ToString(), "");<br />
<br />
proxyObject.BypassProxyOnLocal = true;<br />
<br />
GlobalProxySelection.Select = proxyObject;<br />
req.Proxy = WebProxy.GetDefaultProxy();<br />
req.Proxy=proxyObject;<br />
}<br />
<br />
req.Referer=referer;<br />
req.ProtocolVersion = HttpVersion.Version11;
req.AllowAutoRedirect = true;<br />
req.UserAgent = "Mozilla/4.0";<br />
req.CookieContainer = CookieCont;<br />
<br />
WebResponse result = req.GetResponse();<br />
Stream ReceiveStream = result.GetResponseStream();<br />
Encoding encode = System.Text.Encoding.GetEncoding("ISO-8859-1");<br />
StreamReader sr = new StreamReader( ReceiveStream, encode );<br />
<br />
return(sr.ReadToEnd());<br />
}<br />
catch(WebException ex)<br />
{<br />
string message = ex.Message;<br />
HttpWebResponse response = (HttpWebResponse)ex.Response;<br />
if(null != response)<br />
{<br />
message = response.StatusDescription;<br />
response.Close();<br />
}<br />
txtStatus.Text += message;<br />
return("Internal error opening Site\r\n"+message.ToString()+"\r\n");<br />
}<br />
catch(Exception ex)<br />
{<br />
txtStatus.Text += ex.Message;<br />
return("Internal error opening Site\r\n"+ex.Message+"\r\n");<br />
}<br />
<br />
}<br />
|
|
|
|
|
That's how HTML works, I don't think you can do much, short of parsing the retrieved HTML for frame tags and retrieving the actual pages.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
hmm, thx, sounds very right...
well, the html file (frame?) i got doesnt have any frame tags. how do i prevent my app from loading one specific frame? i disabled autoredirect but still i get a frame (and no information about other frames ) shouldnt there be a super frame or something containing information about all frames within this site? (im not that into html...)
|
|
|
|
|
Can you post the contents of the HTML file? I'm not sure how you can get frames when there are none in the HTML file.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
i just tried again with some other sides. it seems httprequest gets ALL frames, just like firefox would get the site. i just didnt realize it because the site i tested redirected me to another site. SORRY.
|
|
|
|
|
Hi All
Can i compile C# code at runtime? If yes how?
And how can i use it in my code?
Thanks & Regards
Sumit Domyan
|
|
|
|
|
why? look into c# scripting
IM PROUD TO BE A GMAIL;
|
|
|
|
|
You need to look under the Microsoft.CSharp namespace. You can use the CSharpCodeProvider class and get a compiler using the CreateCompiler method. Something like (From MSDN)
Microsoft.CSharp.CSharpCodeProvider provider = new CSharpCodeProvider();
System.CodeDom.Compiler.ICodeCompiler compiler = provider.CreateCompiler();
compiler.CompileAssemblyFromFiles(...);
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Technically, isn't C# code complied at run time?
/\ |_ E X E GG
|
|
|
|
|
|
Hi guys, I 've made a simple program that access a resource and read and write it. The program works fine, but I would like to know if my code is good or there is a better way to do the same.
Thanks a lot for helping me :->
using System;
using System.Collections;
using System.Threading;
namespace ReadersAndWriters
{
///
/// Summary description for Class1.
///
public class BookSeats
{
private bool bAccess = true;
public SortedList Seats = new SortedList();
public BookSeats()
{
for(int i = 0 ; i <= 9 ; i++)
{
Seats.Add(i, 0);
}
}
public int this[int iIndex]
{
get
{
if(!bAccess)
{
Monitor.Wait(this);
}
return (int) Seats[iIndex];
}
set
{
if(bAccess)
{
bAccess = false;
lock(this)
{
Seats[iIndex] = value;
bAccess = true;
Console.WriteLine("Thread {0} acionada", Thread.CurrentThread.Name);
Monitor.Pulse(this);
}
}
else
{
Monitor.Wait(this);
}
}
}
}
public class Client
{
private Random rGen = new Random();
private int iSeat = 0;
private BookSeats m_BookSeats;
public Client(BookSeats Seats)
{
m_BookSeats = Seats;
iSeat = rGen.Next(0, 9);
}
public void MakeReservation()
{
m_BookSeats[iSeat] = 1;
}
public void CancelReservation()
{
m_BookSeats[iSeat] = 0;
}
public void QueryReservation()
{
for(int i = 0 ; i < m_BookSeats.Seats.Count ; i++)
{
if(m_BookSeats[i] == 0)
{
Console.WriteLine("Thread {0} lendo", Thread.CurrentThread.Name);
}
else
{
Console.WriteLine("Lugar reservado");
}
}
}
}
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
BookSeats Seats = new BookSeats();
Client ClientOne = new Client(Seats);
Client ClientTwo = new Client(Seats);
Thread ClientOneMR = new Thread(new ThreadStart(ClientOne.MakeReservation));
ClientOneMR.Name = "Reserva Cliente 1";
Thread ClientTwoMR = new Thread(new ThreadStart(ClientTwo.MakeReservation));
ClientTwoMR.Name = "Reserva Cliente 2";
//Thread ClientOneCR = new Thread(new ThreadStart(ClientOne.CancelReservation));
//ClientOneCR.Name = "Cancela Cliente 1";
//Thread ClientTwoCR = new Thread(new ThreadStart(ClientTwo.CancelReservation));
//ClientTwoCR.Name = "Cancela Cliente 2";
Thread ClientOneQR = new Thread(new ThreadStart(ClientOne.QueryReservation));
ClientOneQR.Name = "Consulta Cliente 1";
Thread ClientTwoQR = new Thread(new ThreadStart(ClientTwo.QueryReservation));
ClientTwoQR.Name = "Consulta Cliente 2";
ClientOneMR.Start();
ClientTwoMR.Start();
//ClientOneCR.Start();
//ClientTwoCR.Start();
ClientOneQR.Start();
ClientTwoQR.Start();
}
}
}
|
|
|
|
|
I am trying to create a database with specific DataFiles and LogFiles in C#. For the life of me I can not figure out how to write the statement for the Datafile part. I found some VB6 code on the Microsoft web site and am having diffuculty converting this line:
-----------------------------------------------------------
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
-----------------------------------------------------------
Here is the complete code:
Dim oDatabase As New SQLDMO.Database
Dim oDBFileData As New SQLDMO.DBFile
Dim oLogFile As New SQLDMO.LogFile
oDatabase.Name = "Northwind"
' Define the PRIMARY data file.
oDBFileData.Name = "NorthData1"
oDBFileData.PhysicalName = "c:\program files\microsoft sql server\mssql\data\northwnd.mdf"
oDBFileData.PrimaryFile = True
' Specify file growth in chunks of fixed size for all data files.
oDBFileData.FileGrowthType = SQLDMOGrowth_MB
oDBFileData.FileGrowth = 1
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
' Define the database transaction log.
oLogFile.Name = "NorthLog1"
oLogFile.PhysicalName = "c:\program files\microsoft sql server\mssql\data\northwnd.ldf"
oDatabase.TransactionLog.LogFiles.Add oLogFile
' Create the database as defined. Note: Create and connect of SQLServer
' object used is not illustrated in this example.
oSQLServer.Databases.Add oDatabase
Thanks in advance for your help
SAG, CANADA
|
|
|
|
|
Hi, i want to make an installer for a executable file, that can install my program in the computer, can any one guide me.thankx
|
|
|
|
|
You can find a lot of free installer programs on the WWW.
The easiest way is create the "setup" in WinRar or WinZip. The noder easy way is to create a Setup project in VS.NET
And I suggest you some installer program, I use:
- QSetup (it's good because can test target machine for Framework)
- Install Shield (good, but complicate and must pay a lot for it)
- Inno Setup (good, and as I remember it's free)
- Setup2Go (good, and as I remember it's free)
That's all I can help you.
|
|
|
|
|
Visual Studio .NET 2003 comes with an Installer project type. If all you want to do is put the application where the user wants to and have a desktop/Programs menu link, then it will do fine. Look for "Setup And Deployment Projects" in the New Project dialog.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|