Failed Using C# To start TASM - c#

Thanks before, i experienced some problem. I'm on project working on my Assembly IDE. I use TASM for the compiler. My C# Code fro compiling is this :
void Compile(string file){
ProcessStartInfo pInfo = new ProcessStartInfo("tasm.exe",file);
Process.Start(pInfo);
}
But i dont know why, when i open TASM with this code. TASM only show a blank black screen. Any suggestions ?

Try this:
void Compile(string file){
Process.Start("tasm.exe",file);
}
That seems more inline with the examples given here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx
I'm assuming 'file' is the full path to the assembly source file you want to assembly.

Related

Notepad ++: CS script Error CS0009 for reading CoolProp.dll file

Some background: I am a newbie to C# and programming in general. Utilizing notepad ++ for my script writer and compiling the program through the command prompt. I am using the CS-script plug in for building CS projects. I am a full time mechanical engineer and trying to utilize an open source alternative to Refprop which is CoolProp (https://github.com/CoolProp/CoolProp) for pulling fluid properties for refrigeration equipment sizing. Trying to develop tools for myself in component evaluation in design.
The problem: I have saved the CoolProp.dll file in the same location to the CS script that I am writing. The CS-Script has found the .dll file for reference but still outputs a CS0009 error. I have tried to trouble shoot the issue by looking through the CoolProp, CS-Script, and CS0009 error discussions on stack overflow. No luck...
Below is my source code (not much written because I am trying to troubleshoot this issue):
//css_args /ac
using System;
using CoolProp;
public class SystemTools.cs
{
public static void Main()
{
double p;
p = CoolProp.PropsSI("P", "T", 300, "D", 1, "Propane");
}
}
Thanks for the help in advance everyone.

'System.IO.FileLoadException' with newtonsoft-json

The debugger keeps giving me this 'System.IO.FileLoadException' error message in the output window of Visual Studio everytime I call the toJSONString() method in a dll assembly I had created earlier. See method below. I used NuGet to load and reference the newtonsoft-json.dll library, so why a runtime attempt keeps failing is beyond me.
Object output;
...
public String toJSONString()
{
String strOut = "";
if (output != null)
{
strOut = JsonConvert.SerializeObject(output);
}
return strOut;
}
In the Solutions Explorer window, under References, I checked the path for Newtonsoft.Json which is C:\temp2\DataTables_Examples\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll. That dll file does exist there. I don't know why the app doesn't see it? Any help would be appreciated.
It may be an issue with your package versioning.
Try this solution presented for someone with a similar error.
Have you any software opened, that is viewing the library or a folder of it?
(like NotePad++ or whatever) Also it would be better, if you include the package directly in your project. Maybe you should try to find out, if the file exists for your studio(https://msdn.microsoft.com/en-us//library/system.io.file.exists(v=vs.110).aspx).
(example from the page)
string curFile = #"c:\temp\test.txt";
Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");
Maybe this link also helps, to check your (studio)acces rights:
Checking file/folder access permission

Reading the Version number from a AssemblyInfo.cs file

I'm trying to extract the version number from a AssemblyInfo.cs file!
And I'm trying to use System.Reflection.Assembly.LoadFile(path); But while doing this I get a BadImageFormatException; "The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)". So now I wounder, is that not a possible way to go about it? And should I use RegEx instead?
I have read many examples with GetExecutingAssembly() but I do want to get the version from an other project.
Clarification: I want to read the version info from the AssemblyInfo.cs file! And not from a compiled file. I'm trying to make a tool to update my version numbers before I make a new release.
You can get Assembly version without loading it as:
using System.Reflection;
using System.IO;
...
// Get assembly
AssemblyName currentAssembly = AssemblyName.GetAssemblyName(path);
Version assemblyVersion = currentAssembly.Version;
Edit:
If you want to read file then you can do it like this:
string path = #"d:\AssemblyInfo.cs";
if (File.Exists(path))
{
// Open the file to read from.
string[] readText = File.ReadAllLines(path);
var versionInfoLines = readText.Where(t => t.Contains("[assembly: AssemblyVersion"));
foreach (string item in versionInfoLines)
{
string version = item.Substring(item.IndexOf('(') + 2, item.LastIndexOf(')') - item.IndexOf('(') - 3);
//Console.WriteLine(Regex.Replace(version, #"\P{S}", string.Empty));
Console.WriteLine(version);
}
}
//Output
1.0.*
1.0.0.0
Hope this help...
You can specify the target assembly path in AssemblyName.GetAssemblyName
AssemblyName.GetAssemblyName("ProjectB.exe").Version
AssemblyInfo.cs file gets compiled to IL assembly.
If you load that assembly you can read the version with all the examples that you have already seen. Which is reading an embedded version information from a compiled assembly file, and it may be overwritten by compilation process to a value different from what is in AssemblyInfo.cs
However it sounds like what you want instead is to read a version number from AssemblyInfo.cs text file, without compiling it down.
If this is the case you really just have to use regex with a format appropriate for your project, or even come up with a convention that will keep it simple.
This could be as simple as
var versionMatch = Regex.Match(File.ReadAllText(filename), #"AssemblyVersion\s*\(\s*""([0-9\.\*]*?)""\s*\)");
if (versionMatch.Success)
{
Console.WriteLine(versionMatch.Groups[1].Value);
}
You would have to consider convention around what goes there, since 1.0.* is a valid version string that translates to timestamp values of form 1.0.nnn.mmm at compile time, and nnn and mmm part closely guessable but not precisely guessable.
It sounds like you're trying to load an assembly compiled for x86 in an x64 environment or vice-versa.
Ensure the assembly this code resides in is built for the same environment as the target and you can get it with the examples it sounds like you've read.
You can proceed with Assembly.GetName().Version where your assembly could be the type of your class
public class Test
{
public static void Main()
{
Console.WriteLine("Current assembly : " + typeof(Test).Assembly.GetName().Version);
}
}
For the test application I have working on, shows me below details using above code:

Null Reference Exception with System.Reflection.Assembly

I have developed a Library for internal email reporting. When I am using that Library from another project (By Adding Reference).
It gives NullReferenceException on the following line.
System.Reflection.Assembly.GetEntryAssembly().GetName().Name
Any idea, why Assembly is null?
This is expected especially in the Windows Services where they are loaded by an unmanaged runtime.
Use:
Process.GetCurrentProcess().MainModule.FileName
To get unmanaged entry point file.
Update
It seems you are looking for this:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
problem is solved guys,
I am using
Assembly.GetAssembly(ex.TargetSite.DeclaringType.UnderlyingSystemType).GetName().Name
to get the EntryAssemblyName.
In this case I already has parameter which is taking Exception 'ex', so I solved it by using that.
Many Thanks Guys, specially #Aliostad
Cheers
Answering both the OP's and #Neeraj 's questions: sometimes it can also be useful to get the root of your assembly with Assembly.GetExecutingAssembly().Location (e.g. when the Resharper test runner is making your life hard when using GetEntryAssembly())
string rootDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string someFile = Path.Combine(
rootDir ?? throw new InvalidOperationException(),
"Foo",
"Bar.txt");

What does "Unhandled Exception: GLib.GException: Unhandled tag: 'requires'" mean?

I'm trying to get my linux Gtk# application working on Windows. When I try to run it, I get this error message:
Unhandled Exception: GLib.GException:
Unhandled tag: 'requires'
at Gtk.Builder.AddFromFile(String
filename)
at Interface.MainWindow..ctor()
at [My Project Name].MainClass.Main(String[]
args) in c:\Path\To\Main.cs:line 10
It seems to be happening when trying to build the interface from my Glade file. I've checked and the path to the glade file is correct. What might be going wrong?
Here is some code to reproduce the problem:
using System;
using Gtk;
namespace TestGtk {
class MainClass {
public static void Main (string[] args)
{
Application.Init();
string gladefile = #"C:\path\to\gladefile.glade";
Builder builder = new Builder();
builder.AddFromFile(gladefile);
Application.Run();
}
}
}
Strange... I don't know why on windows GTK# does not support requires. Anyway I'd try to remove the <requires ... /> tag from gladefile.glade.
This most likely means that your Glade file is corrupt or has got some weirdness in it.
You're using GtkBuilder to load GladeXML files. GtkBuilder has different XML format, incompatible with GladeXML (it more generic). If you use glade-3 to design your UI, you have an option to save as GtkBuilder XML or GladeXML. Also, glade has utility called gtk-builder-convert that you can use to convert GladeXML to GtkBuilder XML.
So, there are two options:
Use glade-3 and save your UI in GtkBuilder format
Use gtk-builder-convert utility
Glade is for GTK 3.x and your system is probably on GTK 4.x.
I had a similar issue when the version was not specified in a Python app using a .glade file, and upon running it would show:
Use gi.require_version('Gtk', '4.0') before import to ensure that the right version gets loaded.
It worked prior to an Ubuntu update last I ran if. After adding
import gi
gi.require_version("Gtk", "3.0")
It works.
A similar issue was noted in a Haskell app. I am not sure how one changes the reference to GTK3 on C#.

Categories

Resources