|
I'm using the following code to run REGASM.EXE to register and create TLB files for some .NET assemblies. The output message indicates that the registration of each assembly was successful however since they are under an installation folder in C:\Program Files, the output message from REGASM doesn't show the full path of the assembly that was registered or exported as a tlb. It just shows 'C:\Program'. Is there any way to fix the output message so that it shows the full path?
private static bool ExecuteAndWait(string _FileToExecute, string _CommandLine, ref string _outputMessage, ref string _errorMessage)
{
Process p = null;
try
{
p= new Process();
p.StartInfo.FileName = _FileToExecute;
p.StartInfo.Arguments = _CommandLine;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.Start();
_errorMessage = p.StandardError.ReadToEnd();
p.WaitForExit();
_outputMessage = p.StandardOutput.ReadToEnd();
p.WaitForExit();
if (p.ExitCode != 0)
{
return false;
}
return true;
}
catch (Win32Exception _Win32Exception)
{
Console.WriteLine("Win32 Exception caught in process: {0}", _Win32Exception.ToString());
return false;
}
catch (Exception _Exception)
{
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
return false;
}
finally
{
p.Close();
p.Dispose();
p = null;
}
}
|
|
|
|
|
One thing I see wrong is your don't need to p.WaitForExit() twice. The process REGASM.EXE will only exit one time.
Do it more like this:
p= new Process();
p.StartInfo.FileName = _FileToExecute;
p.StartInfo.Arguments = _CommandLine;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.OutputDataReceived += new DataReceivedEventHandler(p_DataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(p_DataReceived);
p.Start();
p.BeginErrorReadLine();
p.BeginOutputReadLine();
p.WaitForExit();
Then:
void p_DataReceived(object sender, DataReceivedEventArgs e)
{
outputmsg += e.Data;
}
Edit:
Of course I just made the error and standard messages go to the same event. You could seperate them if you wanted.
|
|
|
|
|
Wouldn't you need some sort of delegate to do that though? Sorry, I'm still a bit green on C#.
|
|
|
|
|
new DataReceivedEventHandler
That is the delegate.
|
|
|
|
|
Thanks. It's still works and it's still doing what it was doing before.
The output passes back a string chopped of path where the tlb file was saved.
ex: "C:\program "
It should bein the following format: C:\Program Files\<app fold="">\<datafolder>\<dllname>
|
|
|
|
|
Wait a second... Is the REGASM.EXE cutting it off or is it only being cut off when using the Process code?
If you ran the REGASM.EXE from a command prompt does it still cut off the c:\Program?
|
|
|
|
|
Jacob D Dixon wrote: Wait a second... Is the REGASM.EXE cutting it off or is it only being cut off when using the Process code?
If you ran the REGASM.EXE from a command prompt does it still cut off the c:\Program?
I checked the command line I was passing and I was inadvertently prepending an extra full path of regasm.exe. Not sure why but it was still registering and creating the Tlb. I took off the extra regasm.exe and started getting the following error:
RegAsm : error RA0000 : The name of the type library cannot be specified for assemblies containing embedded type libraries
What I need and haven't figured out how to do is to add double quotes around to full path of the dll and the full path of the destination tlb because one of the folders in the path is "Program Files".
The command line should look something line this:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe "C:\path\to\dll\mydll.dll" /tlb: "C:\path\to\dll\mydll.tlb"
Ok.. I fixed it. This is what I needed.
string szCmdLine = "\"" + szAssemblyPath + "\"" + " /tlb: \"" + szTlbPath + "\"";
modified on Wednesday, December 1, 2010 3:58 PM
|
|
|
|
|
Awesome! Glad it is working for you.
|
|
|
|
|
Well Spotted.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
JDM6763 wrote: _errorMessage = p.StandardError.ReadToEnd();
p.WaitForExit();
this sequence doesn't make much sense: ReadToEnd returns what is currently available without waiting, so waiting for the process end after that is meaningless. One way to fix things is first wait for end of process, then ReadToEnd on both streams. Alternatives with events or extra threads would allow to capture (lots of) output while the process is still running.
|
|
|
|
|
Perhaps this[^] might be of some use?
|
|
|
|
|
Thanks for the suggestion! What I need to do is fairly simple. I don't think it really needs to be this complex.
|
|
|
|
|
am a beginner in C# programing and i would like to write a program that will be able to register student' data by using Microsoft access for the database. thanks
|
|
|
|
|
Are you a beginner programmer, or just a beginner in C#? This is an important distinction.
The step you need to take before you even open up your code editor is to actually define your requirements. Start off by finding out what the user data is that you need to capture. It's pointless us giving you detailed help if you don't know what it is you are trying to capture. Work out what the business process is for capturing the data. For instance, is there an authorisation process? Does data have to be approved by an authorised user before it can be used elsewhere? Does it need any external interfaces?
While you are doing this, if I were you, I'd get a book on C# development and work through it. Pay particular attention to the sections on database programming - this is where you're really going to need to knuckle down and learn the topic. Also, you need to decide whether the data is going to be managed via a desktop application or a web application, and learn the ins and outs of those particular areas.
|
|
|
|
|
If you use a search engine to search the web for student database, you will find lots of useful information.
FYI: Questions as general as this do not go down well on The Code Project. It makes it look as if you have done no work yourself and you will get lots of messages telling you that no-one is going to do your work for you.
Once you have started coding your application and encounter a problem then by all means ask here. Remember to be specific, paste in error messages in full, if you get any. Include a code snippet for the section of code giving you problems and indicate the problem line(s).
Good luck.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
hi,
i used tab control in windows form , and i added five tab pages in tab control
,and i added 2 datagridview controls in each and every tab page and binding data for all Datagridviews
in From_Load Event .In Form Displayin with Filckering, so how to stop flickering for form loading.Could
you suggest me better way.
Regards,
Vishnu.
|
|
|
|
|
This[^] thread may help you.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Hi,
This is probably a design issue really. I have an object which is AbsMyObject (abstract). Now, what I am currently doing is testing what type it is, and passing it in to a method like this;
if (AbsMyObject is type1)
myMethod((type1)AbsMyObject);
if (AbsMyObject is type2)
myMethod((type2)AbsMyObject);
Im just overloading 'myMethod' so depending on what type my object actually is, a different method is called. Whilst this implementation works as expected, im ending up with tons of these "if object is" If statements and it just feels like a bad design. It also feels like this might have been encountered before and so there might be a better way of achieving this
Any pointers would be greatly appriciated!
Regards,
|
|
|
|
|
Hi,
Why not doing your tests inside your method ? This way, you wouldn't have to care about it when you call your method.
For example :
private void myMethod(AbsMyObject myObject)
{
if (myObject is type1)
{
}
else if (myObject is type2)
{
}
else
{
}
}
|
|
|
|
|
You're right - it sounds like an absolute design nightmare. If you just want to do something different inside your concrete implementation classes, why not rework it so that you use the same method for each implementation? That way, you completely remove the need to know about the implementation? By doing this, you will create a much more loosely coupled application.
|
|
|
|
|
What do you mean by 'abstract'? that it is an abstract class? Which I believe cannot be instantiated so is AbsMyObject of a type that inherits from an abstract class?
If this is the case the your absract class can identify a common function such as MyMethod. Then each of your inheriting class types can implement this function in its own way.
Then you can call function like so...
((AbstractClass)AbsMyObject).MyMethod();
...maybe I am misunderstanding what you are trying to do, if this is way off then please further explain what you are trying to achieve and what you are working with (class/type wise)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thank you all for your replies!
This is what I need in this case;
"If this is the case the your absract class can identify a common function such as MyMethod. Then each of your inheriting class types can implement this function in its own way."
I knew something was wrong with it but didn't quite know how to alter it. This works much better and each object can just have its own implementation of the method. My design skills are a bit poor at the moment
Thanks!
|
|
|
|
|
No problems also be aware that there an Interface is similar to a abstract class in what it may be used for. I don't know your exact requirements but if you don't know about Interfaces then you might want to check them out.
Here is a comparison between Abstract classes and Interfaces which may identify if you could make use of an Interface instead...
Abstract Class versus Interface[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I'm just doing the schoolboy error check, so don't take this amiss, are you sure you haven't really got:
AbsMyObject.MyMethod();
I.E. The method really belongs in the AbsMyObject class rather than the caller?
Also I tried this (to make sure I wasn't about to make a schoolboy error ) and it works without the cast:
public abstract class Foo { }
public class Bar : Foo { }
public class Baz : Foo { }
public class Qux : Baz { }
public class Quux : Foo { }
class Program
{
static void MyMethod(string id, Foo arg) { Console.WriteLine("{0} Called Object Type {1}", id, arg.GetType()); }
static void MyMethod(Foo arg) { MyMethod("Foo", arg); }
static void MyMethod(Bar arg) { MyMethod("Bar", arg); }
static void MyMethod(Baz arg) { MyMethod("Baz", arg); }
static void Main(string[] args)
{
MyMethod(new Bar());
MyMethod(new Baz());
MyMethod(new Qux());
MyMethod(new Quux());
Console.ReadLine();
}
}
Sorry if I misunderstood your problem, but you are right, such if statements have a bad code smell. [Edit]: If those two options don't apply, Pete's suggestion is good. Can MyMethod be refactored to accept the base class and handle the class based differences inside it?
|
|
|
|