My project is a C# NET Framework 4.8 web app that utilizes a Resources folder (with files built as Embedded Resources) to fetch templates at runtime.
Recently I converted it from VB to C# using a very nice Code Converter. While it worked fine, now it seems the structure of the manifest resources has changed, as shown by Assembly.GetManifestResourceNames().
For example, what used to be App.IssueNotification.html is now listed as App.Resources.EmailTemplates.IssueNotification.html .. matching the folder structure in the solution, but forcing me to make changes.
My questions are
What is this VB/C# difference actually called? Is there documentation?
Is there a setting or flag to use the "flatten" resource names like VB does so I don't need to update my code?
You can use vb library inside C# projects, is not an option for you to do it so?, this way you would not need to convert the project you can just easily access to it as an any .dll (library)
I have an issue including a self-built library to a C#-project. I have created an own class library called ClassLibrary1 just to learn how to add libraries on Visual Studio 2019.
So I have written some simple code in a newly created .NET-class library project and have clicked on "create new solution" (directly translated from my german IDE-language. Maybe it's called slightly different) after writing the code. Back in the C#-project, I have selected the dll-file from bin/Debug/ of the class library's project folder.
After I have set the checkmark, the dll-file was shown in the solution-explorer under Assemblys like expected. But the issue I now have is that I still cannot use the ClassLibrary1.dll-file in the cs-file in this very project as I expected via the command "using ClassLibrary1;". It only shows me the error message "type- or namespacename "ClassLibrary1" not found" when trying to compile the C#-project and I don't get, why this is the case.
It seems like it has to be a very obvious problem but after some research on the internet and trying some things by myself still nothing has changed.
Thanks in advance for helpful replies.
The by far easiest way to manage a library is to use project references. Ensure that your library and the project that uses the library is in the same solution. Then right click the "references" and select "add Reference", go to the project tab and add a checkbox for the library. Read more about managing references.
You might also need to add namespaces for the classes you wish to use in the source files.
I would not recommend managing using file-references to lose dll-files, since it can easily become a hassle to manage. I.e. if you create a new version of the library you would need to build, and explicitly replace this file in all other projects and update all the references.
If you want to share libraries between multiple solutions the more popular solution would be to setup a nuget server. This solves some of the updating problems by maintaining multiple versions of the same library, and provides a nice interface to update references in all projects. But this is a somewhat more complicated solution, so I would not recommend this for new developers.
I currently have a library which was created in a silverlight application for its use. But Now we are switching over to WPF. So i don't know how would i convert the library to a wpf library. Would i just have to copy all the file in a new project(wpf class library)
As you can see when i reference this silver light library in my wpf project. It gives me a warning.
As the message says, you can't use a project compiled to target Silverlight as a reference for a project targeting some other .NET framework family. You will need to compile a separate assembly compatible with the .NET framework family you're using (i.e. a desktop version). This will require the creation of a whole new project (I'm not aware of a practical way to have a single project target both Silverlight and desktop .NET).
Note that the new project can use the same source files as the original Silverlight one. After creating the project (which you should create as an "Empty Project"), you can add the source files from the Silverlight project, by using the "Add Existing..."/"As Link" option for adding items to the project. Adding the source code as links will cause the new project to reference the original .cs files in their current location rather than creating a new copy of them for the new project.
Note also that your Silverlight code may or may not be 100% compatible with the WPF API. You may have to introduce conditional compilation (i.e. use #if, and declare appropriate conditional compilation symbols, in the projects' settings "Build" tab) so that you can provide correct code for each platform in each .cs file.
Related topics (there a lot of duplicate questions involving adding existing items as links…though many of these involve multiple solutions, not just adding items to a new project):
Share c# class source code between several projects
How do I keep common code shared between projects in c#?
Adding Existing Files To Different Visual Studio 2010 Project
Is it possible to statically share code between projects in C#?
Updating classes used in multiple projects?
Make reference to C# code from multiple projects
Share .cs file among VS 2010 C# projects
How to include source files of one project in another project?
I have an Obj-C native library libCMX.a that I wish to create C# bindings for, but the library has multiple dependencies, e.g. JASidePanels with a couple of .m and .h files.
How can I include these in the Xamarin binding project so they are linked correctly into the resulting DLL?
I know I can specify Frameworks in the LinkWith attribute, but how do I include pure code dependencies in form of main and header files?
EDIT: The library is proprietary (Cisco CMX SDK), I do not have access to the source code.
EDIT 2: The library is part of a framework (CMX.framework), from which I have extracted the extensionless archive and renamed it to libCMX.a to match default library naming for Xamarin.
You can reference multiple native libraries in your binding project, the combined set of libraries will be linked into your application.
You only need to surface the APIs for libraries that you want to invoke/call. For the rest, just include the binary dependencies.
You will need to compile those into the static library (libMyLibrary.a) you are binding to C#.
This question is kind of lengthy but I try to provide you with the details that I think is necessary to find the answer.
I have a C# WPF solution (.Net 4) consisting of a main project, building a WPF windows app, which depends on a few class library projects residing in the same Visual Studio 2010 solution.
One of the class library projects encapsulates some previously developed python code that I want to make use of through IronPython and Microsoft Dynamic Language Runtime.
I would like the class library project to be self contained and not depend on a complete installation of IronPython.
The problem is that I don't know how to refer to the encapsulating library project holding the python code in a way that always work.
Normally I would just add a reference to the class library project as discussed in this question: Visual Studio 2010: How refer to a C# .Net class library project with third part dependencies. However it did not help.
How the solution is set up in Visual Studio:
The solution looks like this:
MainApp (windows WPF application project)
...
ClassLib1 (C# class library project)
...
ClassLibWithPython (C# class library project with IronPython)
C# classes
lib (directory)
IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.dll
Microsoft.Scripting.Metadata.dll
pylib (directory with some used python modules)
os.py
... .py
ctypes (directory with some used python modules)
my pyton classes (directory)
ClassLibWithPython has references to the IronPython DLLs residing in its local lib folder (Copy Local attribute True). The MainApp project has references to ClassLib1 project and ClassLibWithPython project (also with Copy Local attribute True).
When compiling the solution all DLLs and the MainApp.exe file shows up in MainApp/bin/Debug and it works fine on some machines (XP and Win 7) however it fails on some other machines (XP). After doing some debugging I've found that the built-in IronPython modules are not loaded correctly. When importing the os module (pylib/os.py like this one http://pydoc.org/get.cgi/usr/local/lib/python2.5/os.py) I get a python exception (ImportError, no os specific module found) due to missing module name 'nt'.
When comparing what's happening where it works and where it doesn't I've found that sys.builtin_module_names just returns a few items compared to what I get when running the same code on some other machines.
Problematic machine has:
sys.builtin_module_names = ['clr', 'future_builtins', 'imp', 'sys', '__builtin__', 'exceptions']
Computers where everything works have:
sys.builtin_module_names: ['clr', 'future_builtins', 'imp', 'sys', '__builtin__', 'exceptions', '_codecs', 'cmath', '_sha512', 'msvcrt', 'array', '_winreg', '_weakref', '_warnings', '_subprocess', '_ssl', '_sre', '_random', '_functools', 'xxsubtype', 'time', 'thread', '_struct', '_heapq', '_ctypes_test', '_ctypes', 'socket', '_sha256', '_sha', 'select', 're', 'operator', 'nt', '_md5', 'math', 'marshal', '_locale', '_io', 'itertools', 'gc', 'errno', 'datetime', 'cStringIO', 'cPickle', 'copy_reg', '_collections', 'binascii', 'zlib', 'signal', 'mmap']
Work-around that didn't help
I've tried to add using statements to the C# code of ClassLibWithPython to make sure even the implicitly referenced assemblies are linked, but with no difference.
Work-arounds that helped
I've found two workarounds providing a working solution, however both of them breaks the encapsulation principle and exposes the implementation details of ClassLibWithPython:
Put all code from ClassLibWithPython in the MainApp project instead.
Keep ClassLibWithPython in a separate project but add references to IronPython.dll and IronPython.Modules.dll to the MainApp project as well.
What is it that make work-around #2 working?
Any suggestions how to make this work in a clean way?
Thank's for reading this far ;-)
I don't fully understand the deployed layout - but try the following.
1) For modules that you expect to be loaded from IronPython.Modules.dll ensure that this assembly is available in your deployment location, and/or hook AssemblyResolve (see here) event if this assembly is in a different location.
2) For modules that you expect to be loaded from a py module. Ensure the probing location is added to sys.path via sys or from the DLR hosting API. eg sys.path.append(...)