I googled and someone found the answer and linked but it was dead. How can i find a specific class in a specific file? The poster i found ask that question and found how to do it in a namespace but i would like to find one specific to a file. This question is to answer my other question but now that i thought of this i would like to know the answer.
Something like this?
string path = "INSERT PATH HERE";
var assembly = Assembly.LoadFile(path);
foreach (var type in assembly.GetTypes())
{
Debug.WriteLine(type.Name);
// do check for type here, depending on how you wish to query
}
I am not sure how the file name shall be stored as part of compiled assembly. Other option is that you can use the PDB file generated by the VS IDE to get the source file at some extension.
Here is some internals of pdb file.
http://www.informit.com/articles/article.aspx?p=22685
Once you can parse the file, you can use the symbol and look at the source definition.
I am glad to know other ways as well.
If you want to find the source code for a class, use the Go To Definition option in Visual Studio.
Once the code is compiled, it's not arranged in files, it's arranged in name spaces and assemblies. If it's at all possible to find out from which source file a class originated, you would have to loop through all classes and look for it.
Related
I'm working on combining multiple files with data in them to put it into one big file. I've found the compiler we need on Github here: https://github.com/AndyTWF/sector-file-compiler however I've never worked with this before or even the programming language it is in. This would help us a ton instead of copy-pasting the data one by one as we've got over 100+ files to combine.
I understand that it needs a config.json file which I have configured however I do not know where to specify the path of that file in the CompilerCLI files(?). I also want to know how I can specify where the output files will be.
The repo with the input files that are supposed to be mentioned in the .json file is in this repo https://github.com/VATFrance/FR-Sector-File
I'm a total newbie to this type of stuff so help would be appreciated!
P.S: I have Visual Studio installed already.
Try by adding this flags in your command line to setup configuration file and output
Path to the compiler configuration JSON file :
--config-file [arg]
Where the output file for the EuroScope ESE should be generated :
--out-file-ese [arg]
Where the output file for the SCT should be generated :
--out-file-sct [arg]
I have created two resources files with names:
ManageUserResources.resx
ManageUserResources.zn-CN.resx
Now respective namespaces in designer.cs are:
Resources
Resources.ManageUserResources
//Error: The namespace resources already contains definition for ManageUserResources
Is this conflict between namespace and class(having same names)?
Any solution for this problem?
While creating resource files for name spaces for multiple languages, always make sure you check the correct culture code. In your case the for ManageUserResources.zn-CN.resx. Considering you wanted to select China, it should have been ManageUserResources.zh-CN.resx The code for china is zh-CN and this should not be replaced.
Coming to your problem:
Specifically the error occurs in the Resources.Designer.cs You could just delete the file and let Visual studio regenerate it.
I've had this problem, too, and it was because I created a new namespace, but the parent namespace contained a class with the same name.
To find this, I used the object browser and searched for the name of the item that was already defined.
If it won't let you do this while you still have the error, then temporarily change the name of the item it is complaining about and then find the offending item.
Hope this helps.
I have a file I need to access at runtime, I've included it in my project and set it up as embedded resource (it's actually a source file, I changed the extension to .cs.txt to get around VS trying to compile it. That shouldn't matter, but I'm mentioning it anyway just in case).
When I try getting the file
var assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(resourceName);
I get a null. I've made sure I'm using the Namespace.Folder.Filename notation, but that didn't help. It appears the file is actually not there, because when I call
assembly.GetManifestResourceNames();
I get an empty string array. Any idea what could be the case?
I appreciate this is an old thread but what I found this morning might be useful to others.
I had a resource where the filename had multiple dots in it...
example filename: data.txt.dat
var resources = asm.GetManifestResourceNames(); // None found (empty array)
renamed to data.txt (still just an embedded resource in the project configuration
var resources = asm.GetManifestResourceNames(); // Entry found ("Assembly.Namespace.data.txt")
So maybe there is some limitation around multiple . characters in the name
So I got around this by using the VS resource manager. Now I can access the file directly like this:
MyNamespace.Properties.Resources.MyFile
I'd recommend this approach to anyone, as it seems not only much cleaner, but safer as well. Thanks Hans Passant for the advice.
Based on this pull request (https://github.com/dotnet/msbuild/pull/5824) you can add WithCulture="false" in your csproj on your EmbeddedResource tag :
<EmbeddedResource Include="a.cs.b" WithCulture="false"/>
It is working for me
I know there are many topics similar to this, but I've been unable to find a solution after looking through dozens of results.
I have a Project "Foo", and my controller is at "Foo\Controllers\Bar.cs, and in that C# file, I want to read from a file, located at "Foo\Data\Stuff.txt". It's so simple, but nothing I've tried works, mainly because things like Directory.GetCurrentDirectory() and all similar built-in functions reference the executing directory (in my case, "C:\Program Files (x86)\IIS Express").
What am I doing wrong? Or if I missed an identical question, please direct me there, this seems to small an issue to have spent so much time on. Thanks!
With command Server.MapPath("Foo\Data\Stuff.txt") you will find the phisical path where the file is stored
It sounds like you might be looking for System.Reflection.Assembly.GetExecutingAssembly().CodeBase, which allows you to find exactly where your running .exe is located; regardless of whether you're in the debugger or not.
Here's an example that uses "CodeBase" to find the path, then reads the Windows version info from the .exe:
// GetWindowsVersion: Fetch Winver info from specified file
public static string GetWindowsFileVersion()
{
String codeBaseUri =
System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
String codeBase =
new Uri(codeBaseUri).LocalPath;
System.Diagnostics.FileVersionInfo info = FileVersionInfo.GetVersionInfo(codeBase);
return info.FileVersion.ToString();
}
I'm a VB.NET programmer, but I'm new to C# and now I'm working with C# project which uses local resource files (.resx).
Using VB.NET I can access to variables in resource file via My.Resources.< LocalResourceFile >.< MyVariable > . But in C# I can't find any alternatives for My namespace, but I still can access to resource if I replace My namespace with < MyProjectNamespace >.
Maybe there are any other way to access my local resources?
If you absolutely must use the equivalent of the My namespace, there is actually such a thing in C#. It is the Microsoft.VisualBasic.Devices.MyServices namespace. To use that, you must add a reference to Microsoft.VisualBasic.dll and add using Microsoft.VisualBasic.Devices; to your code file. For this route, see here: http://msdn.microsoft.com/en-us/library/ms173136.aspx
I would not, however recommend doing that. Instead, to access resources, you simply use MyNamespace.Properties.Resources like this:
namespace SomeNamespace
{
...
var myFile = SomeNamespace.Properties.Resources.MyFile;
...
}
You can do this which is virtually the equivalent:
Bitmap image = Properties.Resources.picture000;
It still works the same way, just don't put "My.Resources" in front of the name. So if you added a .resx file named "Resource1" and put a string named "Foo" in the resource then the variable name is "Resource1.Foo".
If you put code in non-default namespaces then you may have to prefix it with the default project namespace. Like "WindowsFormsApplication1.Resource1.Foo". If you are lost then just look at the auto-generated code. In the Solution Explorer window open the node next to the .resx file and double-click the Designer.cs file. Don't edit it.
There is no built-in My namespace, but you can reference Microsoft.VisualBasic.dll and have it.
Check out: http://msdn.microsoft.com/en-us/library/ms173136(v=vs.80).aspx