|
Lets say I have a old executable that was not created in the .NET world that contains a bunch of dll and stuff like that. This old executable takes in command line arguments to generate a specific result. I was thinking about creating a .NET assembly class to wrap this executable. The programmer using this wrapper would be able to specify certain properties and then generate a result.
My question is simple. When deploying this wrapper assembly do I........
1. Store the old executable and dlls into the assemblies Resources.resx and when the user wishes to generate a result make a directory and copy the files into the directory (if they do not already exist) and then generate the result.
2. Attach the old executable and dlls into a folder within the assembly project itself and change the build action to content and when the project is deployed make sure the content files are also deployed with the project.
3. Use another method?
Thanks Chris
|
|
|
|
|
chris175 wrote: 2. Attach the old executable and dlls into a folder within the assembly project itself and change the build action to content and when the project is deployed make sure the content files are also deployed with the project.
That is the option I'd go for. It keeps the app with its DLLs in a known place relative to your application.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
|
Hello!
I want to know how .NET managed threads in STA model application. When I create new thread should I init COM library in some way (like CoInitialize() in C++) or .NET did it for me?
Best regards,
M.
|
|
|
|
|
.NET does it all for you; you don't need to call CoInitialize. Note that if you're using a COM object on a background thread, ensure that the thread is STA. You can do this by calling thread.SetApartmentState before the thread has started executing.
Note that the UI thread for Windows Forms (and WPF, I believe) applications are STA by default, so if you created a COM object on that thread, you'll be fine.
|
|
|
|
|
I get the following error when calling the ReadMultiple method.
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
I don't suppose anyone has a working example of reading the summary information from a file? The annoying thing is that I can write to the summary fields but not read them
<br />
[StructLayout(LayoutKind.Explicit, Size = 8, CharSet = CharSet.Unicode)]<br />
public struct PropSpec<br />
{<br />
[FieldOffset(0)]<br />
public int ulKind;<br />
[FieldOffset(4)]<br />
public IntPtr Name_Or_ID;<br />
}<br />
<br />
[StructLayout(LayoutKind.Explicit, Size = 16)]<br />
public struct PropVariant<br />
{<br />
[FieldOffset(0)]<br />
public short variantType;<br />
[FieldOffset(8)]<br />
public IntPtr pointerValue;<br />
[FieldOffset(8)]<br />
public byte byteValue;<br />
[FieldOffset(8)]<br />
public long longValue;<br />
<br />
public void FromObject(object obj)<br />
{<br />
if (obj.GetType() == typeof(string))<br />
{<br />
this.variantType = (short)VarEnum.VT_LPWSTR;<br />
this.pointerValue = Marshal.StringToHGlobalUni((string)obj);<br />
}<br />
}<br />
}<br />
<br />
[ComVisible(true), ComImport(),<br />
Guid("00000138-0000-0000-C000-000000000046"),<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]<br />
public interface IPropertyStorage<br />
{<br />
uint ReadMultiple(<br />
uint numProperties,<br />
PropSpec[] propertySpecifications,<br />
out PropVariant[] propertyValues);<br />
<br />
uint WriteMultiple(<br />
uint numProperties,<br />
[MarshalAs(UnmanagedType.Struct)] ref PropSpec propertySpecification,<br />
ref PropVariant propertyValues,<br />
int propIDNameFirst);<br />
<br />
uint Commit(<br />
int commitFlags);<br />
}<br />
<br />
PropSpec[] propSpecs = new PropSpec[1];<br />
propSpecs[0].ulKind = 1;<br />
propSpecs[0].Name_Or_ID = new IntPtr((int)summaryType);<br />
PropVariant[] propertyValues = new PropVariant[1];<br />
<br />
hresult = propStorage.ReadMultiple(1, propSpecs, out propertyValues); <br />
Thanks
|
|
|
|
|
Does this Q & A[^] help? A quick google search revealed it.
|
|
|
|
|
Thanks for the link, but I've tried that one already with no luck.
|
|
|
|
|
I need to create pdf files from html files. I have searched it but i couldn't find a real solution.
I used Winnovative but it uses ads. The library must also transfrom html tables.
Are there open source libraries for converting files ?
|
|
|
|
|
|
|
I have used Itextsharp. It doesnt work good when table doesnt fit the page. It can not divide correctly. Also it makes whole widths the same.
|
|
|
|
|
Hello everyone,
I have a problem with one application which should run permanently to transfer some output from a serial port to a database. This application crashes about every 17 hours once which should not happen because of loosing data when the application is not running.
I located the error in this code:
if (tmp.Length > 0) {<br />
while (_conn.State != ConnectionState.Open) {<br />
_conn.Open();<br />
Thread.Sleep(100);<br />
}<br />
cmd.Connection = _conn;<br />
cmd.ExecuteNonQuery();<br />
}
* tmp is a string which contains the edited output of the serial port.
* _conn is an MySQL-Connection made through the MySQL-.NET-Connector 5.0
* cmd is a simple INSERT-Command (MySQLCommand)
So in this context i got the following error:
<br />
exception.source == mscorlib<br />
<br />
exception.message == Non-negative number required.\nParameter name: count<br />
My problem is: I cant see any parameter named count where the exception can happen. Might it be that the MySQL-Connector itself causes that exception? If this is the reason i'll try to rewrite the code for an ODBC-Connection.
I hope i provided all needed information to pass a hint to me.
With best regards,
K. Ahlers
|
|
|
|
|
You haven't posted the query that you are executing towards the DB
anyway try to set on nocount in the query string
Just
Set NOCOUNT ON
and at the end
SET NOCOUNT OFF
maybe it will help
I am not sure
by the way you can use a
DB profiler to check whether your problem emerges from the DB layer
|
|
|
|
|
My query is as I said a simple insert:
string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");<br />
MySqlCommand cmd = new MySqlCommand("INSERT INTO log (datelogged, logentry) VALUES ('" + now + "', '" + tmp + "')");
tmp is here equal to the tmp in my first posting a string from the serial output.
The table is a InnoDB table with the fields id(INT), datelogged(DATETIME), logentry(VARCHAR(200)
With best regards,
K. Ahlers
|
|
|
|
|
Hi,
"parameter named count" refers to a method that has count in it's documentation
(actually its reflected parm list); it does not refer to one of your app's
variables named count. Yhere are many candidates including:
public int SerialPort.Read (
byte[] buffer,
int offset,
int count
)
some suggestions:
- look at the entire exception, that is use exception.ToString(), it will
show all available information including line numbers, message details, and
inner exceptions if any
- have Visual show line numbers (see my sig)
- put a try-catch and have it show all relevant variables when it catches this
or some other exception, including cmd, tmp, ...
and ideas:
- a 16-bit number counting seconds would overflow after 18.2 hours
- you might have a memory leak (or a disk full; logging?) resulting in a
systematic failure; if exceptions are not handled correctly, that might
result in just about any symptom
final comment:
if all the above dont help, show us all available info and some complete methods.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Okay. I added the .ToString() but we have to wait for the next crash to execute...
With best regards,
K. Ahlers
|
|
|
|
|
[quote]make Visual display line numbers: Tools/Options/TextEditor/..[/quote]
Thanks for that... i gave up looking last time I tried.
ps. Another quality response. Out of interest, where are you from Luc?
|
|
|
|
|
Hi,
J4amieC wrote: make Visual display line numbers: Tools/Options/TextEditor/...
it is a shame Microsoft did not turn that on by default; posters ignore line numnbers
in exceptions since they don't show in source files anyway, making them look for
problems everywhere except where they really are.
J4amieC wrote: where are you from
Belgium, a little south of where you are See profile page.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Okay NOW i have a complete error-message:
System.ArgumentOutOfRangeException: Non-negative number required.<br />
Parameter name: count<br />
at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)<br />
at MySql.Data.MySqlClient.MySqlStream.Read(Byte[] buffer, Int32 offset, Int32 count)<br />
at MySql.Data.MySqlClient.MySqlStream.ReadString(Int64 length)<br />
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData41()<br />
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData()<br />
at MySql.Data.MySqlClient.NativeDriver.ReadColumnMetadata(Int32 count)<br />
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()<br />
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)<br />
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()<br />
at Cisco2Mysql.Form1.serialPort1_DataReceived(Object sender, SerialDataReceivedEventArgs e)<br />
So it seems to be really a buggy .NET-Connector or can anyone there a mistake by me?
With best regards,
K. Ahlers
|
|
|
|
|
OK, seems the problem is in your serialPort1_DataReceived method.
Will you find it yourself, or do you plan on showing us the entire method's source code ?
For some reason, we did not get line numbers. Is this release code ?
And this seemed like an 9-hour run, not a 17-hour one ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Good morning Luc,
here is the complete method:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) {<br />
try {<br />
_buffer += serialPort1.ReadExisting();<br />
<br />
int posofbreak = _buffer.IndexOf('\n');<br />
if (posofbreak > -1) {<br />
string tmp = _buffer.Substring(0, posofbreak).Trim();<br />
<br />
if (posofbreak < _buffer.Length - 1)<br />
_buffer = _buffer.Substring(posofbreak + 1);<br />
<br />
while (tmp.IndexOf('>') > -1)<br />
tmp = tmp.Substring(tmp.IndexOf('>') + 1).Trim();<br />
<br />
string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");<br />
<br />
MySqlCommand cmd = new MySqlCommand("INSERT INTO cisco_log (datelogged, logentry) VALUES ('" + now + "', '" + tmp + "')");<br />
<br />
if(box.Text.Length > 5000) <br />
box.Text = box.Text.Substring(0, 5000);<br />
<br />
box.Text = tmp + "\r\n" + box.Text;<br />
<br />
if (tmp.Contains("L11 0")) {<br />
serialPort1.WriteLine("CD EWE");<br />
serialPort1.WriteLine("DISCO 2");<br />
LogWrite("Call detected, disconnecting second line.");<br />
}<br />
<br />
if (tmp.Contains("L67 2")) {<br />
Thread.Sleep(2000);<br />
serialPort1.WriteLine("CD EWE");<br />
serialPort1.WriteLine("CALL 2");<br />
LogWrite("Line Integrity Violation detected, reconnecting second line.");<br />
}<br />
<br />
if (tmp.Length > 0) {<br />
while (_conn.State != ConnectionState.Open) {<br />
_conn.Open();<br />
Thread.Sleep(100);<br />
}<br />
cmd.Connection = _conn;<br />
cmd.ExecuteNonQuery();<br />
}<br />
<br />
}<br />
<br />
buff.Text = _buffer;<br />
}<br />
catch (Exception ex) {<br />
LogWrite("Exception at serialPort1_DataReceived: "+ex.ToString());<br />
}<br />
}
After the "MARKER" the exception is thrown. (Yes it is a release-binary)
With best regards,
K. Ahlers
|
|
|
|
|
Hi,
I looked at your code and have some comments:
1.
you did not follow my advice "put a try-catch and have it show all relevant variables
when it catches this or some other exception, including cmd, tmp, ..."
2.
I don't see why you have the test in
if(posofbreak < _buffer.Length - 1) _buffer = _buffer.Substring(posofbreak + 1);
With it, if _buffer contains just one line ending on \n, that line remains in
_buffer and will be processed again next time DataReceived fires.
3.
while(tmp.IndexOf('>') > -1) tmp = tmp.Substring(tmp.IndexOf('>') + 1).Trim();
could have been handled more elegantly with ListIndexOf
4.
I am not sure the Thread.Sleeps, especially the one with 2000, are a good idea
inside DataReceived; they make your code not react for 2 seconds on the next
data; if for some reason "L67 2\n" comes in every second, you will never
catch up.
5.
I don't know what value serialport1.ReceivedBytesThreshold has; if it is
much larger than 1, chances are you receive more than one line of text every
time, but you only process one line at a time.
Actually, there should have been a while loop: as long as entire lines are
available, process it.
6.
if buffer contains only one line of the form
sometext > \n
then tmp will be an empty string; not sure SQL will like that
I strongly suggest you follow my advice (see 1); I don't understand how you
did not do this from the beginning: when something goes wrong, the more information
you have about it, the easier it is to pinpoint the problem...
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
1) How can I do that? In the try-catch these variables are not longer availiable. How to access them without declaring them global? Or did you mean to define a try-catch inside my existing try-catch?
2) Solved.
4) It must sleep about 2 seconds because the router have to clean up the line before reconnecting. This error can appear only if the line is connected - so not multiple times before reconnecting.
5) Solved.
6) If tmp.lenght is not greater than 0 the SQL-Command will not be executed.
With best regards,
K. Ahlers
|
|
|
|
|
Hi
1.
declare and initialize the var before the try statement (or as a class
member, see _buffer)
6.
sorry, my mistake
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|