Posted on

Retrieve resources in c# Windows Forms .Net Application

Scenario

You have a library (dll) with one or more image and you want to use those image in your application.

Load Resource from application

Consider having a library called : myLibrary.dll with some class inside with Namespace mylibrary.

In your bapplication you can get to the resources by referencing the assembly :

Assembly assem = Assembly.LoadFrom("myLibrary.dll");

You can enumerate the resource files

string[] resNames = assem.GetManifestResourceNames();
if (resNames.Length == 0)
Console.WriteLine(" No resources found.");

foreach (var resName in resNames)
Console.WriteLine(" Resource 1: {0}", resName.Replace(".resources", ""));
foreach (var resName in resNames)
Console.WriteLine(" Resource 2: {0}", resName);

And this will be the output :

Resource 1: myLibrary.Properties.Resources
Resource 2: myLibrary.Properties.Resources.resources

The replace is necessary because the real resource name is the first one (without .resources)

Now, If you have an image called myBitmap.png in your resources, you can load it, using ResourceManager

ResourceManager rm = new ResourceManager("myLibrary.Properties.Resources",
assem);

and finally

Object myres = rm.GetObject(myBitmap);

Load Resource inside Library

To get resource from a class inside your resource library, defined a new class, for example myClass and reference own assembly :

rm = new ResourceManager("myLibrary.Properties.Resources",
typeof(myClass).Assembly);

At this point you can withdraw the resource as seen above.

Posted on

CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

Compiler Error CS1617

Invalid option ‘option’ for /langversion. Use ‘/langversion:?’ to list supported values.

For example

Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

Solution

Right click on your project and select “Properties” from menu.

Select Build menu and, in the bottom, click on button “Advanced”.

In the next form you don’t have any voice for the field “Language Version”

Select “default”

Done

Posted on

c# and shadow copy – notes on library AlphaVSS

AlphaVSS

AlphaVSS is a .NET class library providing a managed API for the Volume Shadow Copy Service also known as VSS

Error loading library AlphaVSS.x64.dll

if you have error loading the library probabilly you need to install on the machine the Visual C++ 2017 Redist package.

You can find it at this link

Control shadow copy

To control shadow copy, created using alphavss library, you have to open a command prompt whith administrative priviliges and type

vssadmin

to list your shadow copy you have to type :

vssadmin list shadows