ConfUserEx excluding a namespace from obfuscation - c#

In ConfUserEX Obfuscation (https://yck1509.github.io/ConfuserEx/)
How to EXCLUDE just one Namespace from rename module?
For example :
[assembly: Obfuscation(Exclude = true, Feature = "namespace 'ABC.XYZ':-rename")]
Looks it does not work. I have a objectmodels for Json parsing in a namespace and this throwing error. Also I am using .crproj file for obfuscating using CLI.

Please download latest version v0.6.0 by this link. Exclude field from true to false. And that's it.
For example:
[assembly: Obfuscation(Exclude = false, Feature = "namespace 'Your.Namespace':-rename")]

According to the documentation , if you want to exclude a namespace, the correct way to do it is to write a line like:
[assembly: Obfuscation(Exclude = false, Feature = "namespace('namespaceToExclude'):-rename")]
This should be written in the Assembly.info file of the project.

Related

How to add Properties.Settings.Default in c#

I am not able to write "Properties.Settings.Default". It is not coming in the dropdown list. Is there any namespace that we can add?
Add your project namespace to the Properties namespace. The default namespace defined in the project settings.
For instance if your project default namespace is MyApp.
MyApp.Properties.Settings.Default
Make sure you are on the same namespace and try to access the properties like this :
namespace.Properties.Settings.Default
or if you are on different namespace don't forget to use
using namespace
An additional hint on top of the above answers:
Go to solution explorer -> Properties folder -> Settings.settings ->
Settings.Designer.cs file
and see which namespace is being used there. Ensure that you are using this namespace in your code file as others have suggested
Once you setup your environment in the settings under properties of the app. You want to reference it to the project like this:
using App.Properties.Settings
Then in the code you write you can use as example:
userName.Settings.Default
In this case userName is set within the settings.
Set your Setting in your project
go to Project => property => go to setting
Set your element (string,int, ecc...)
Save from program all values
Properties.Settings.Default.User = txtUser.Text; Properties.Settings.Default.Password = txtPass.Text;
Properties.Settings.Default.Save();
if you use Windows 10, this is the directory of setting Values:
C:\Users\AppData\Local<ProjectName.exe_Url_somedata>\1.0.0.0<filename.config>

InternalsVisibleTo attribute ignored when compiling solution via Roslyn

So I am developing a Roslyn-based frontend compiler that parses a C# solution, performs rewriting on the syntax trees to desugar some constructs of my DSL, and then uses the Roslyn APIs to compile and emit executables/dlls. This last part, given a compilation, is done very simply like this (some details omitted for clarity):
var compilation = project.GetCompilationAsync().Result;
var compilationOptions = new CSharpCompilationOptions(outputKind,
compilation.Options.ModuleName, compilation.Options.MainTypeName,
compilation.Options.ScriptClassName, null,
compilation.Options.OptimizationLevel, compilation.Options.CheckOverflow,
false, compilation.Options.CryptoKeyContainer,
compilation.Options.CryptoKeyFile, compilation.Options.CryptoPublicKey,
compilation.Options.DelaySign, Platform.AnyCpu,
compilation.Options.GeneralDiagnosticOption,
compilation.Options.WarningLevel,
compilation.Options.SpecificDiagnosticOptions,
compilation.Options.ConcurrentBuild,
compilation.Options.XmlReferenceResolver,
compilation.Options.SourceReferenceResolver,
compilation.Options.MetadataReferenceResolver,
compilation.Options.AssemblyIdentityComparer,
compilation.Options.StrongNameProvider);
var targetCompilation = CSharpCompilation.Create(assemblyFileName,
compilation.SyntaxTrees, compilation.References,
compilationOptions);
EmitResult emitResult = null;
using (var outputFile = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
emitResult = targetCompilation.Emit(outputFile);
if (emitResult.Success)
{
return fileName;
}
}
So everything works perfectly fine, until I tried to compile a solution where a project A declares some internal classes/fields, and then uses the [assembly: InternalsVisibleTo("...")] attribute (in the AssemblyInfo.cs file) to give visibility of these internals to another project B.
Directly compiling using visual studio works perfectly fine and allows B to see these internal declarations of A. However, when I try to compile through my tool using the Roslyn APIs, it is like the InternalsVisibleTo attribute is completely ignored, and I am getting back errors, such as:
error CS0122: ... is inaccessible due to its protection level
Which means the InternalsVisibleTo was not picked up.
I was expecting that Roslyn would automatically pick this up from the parsed project info, but I am now wondering if I have to enable some specific compilation option or to add some information manually?
I have looked around but I cannot find a similar question or an answer, unless I am missing something. I can give some more information if required. Thanks!
InternalsVisibleTo requires matching the public key used for signing the other assembly exactly (or no public key in case of unsigned assembly).
Double check you are providing either that correct key and the correct assembly name including the namespace.
Particularly, here, you are interested to the full public key, and not the public key token.
For more information and how to extract the public key for this purpose, please have a look at InternalsVisibleToAttribute Class.

The name 'File' does not exist in the current context

I am a beginner in c# programming. I am gettting error The name 'File' does not exist in the current context.
Problem must be in the line var v = File.ReadLines("dictionary.txt");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 0)
{
var v = File.ReadLines("dictionary.txt");
Just add this using statement to the top of you file
using System.IO;
The compiler only recognises classes from namespaces that you have in the current context. You add namespace to the context using using statements. You can also use a fully qualified type name such as System.IO.File to refer to the class.
If you are using Visual Studio you can also place the cursor on the problematic symbol (File) and press Shift + Alt + F10
For anyone using Visual Studio 2015 this error will still occur even if System.IO is referenced. The problem is that by default a Visual Studio 2015 project will target both the dnx451 and dnxcore50 frameworks, and the System.IO assembly doesn't seem to be available for dnxcore50.
If you look in the project.json file you'll see a "frameworks" section. The quick fix is to comment out the "dnxcore50" entry so that you're only targeting dnx451:
"dnxcore50": {
"dependencies": {
"System.Console": "4.0.0-beta-22816",
"System.Collections": "4.0.10-beta-22816",
"System.Linq": "4.0.0-beta-22816",
"System.Threading": "4.0.10-beta-22816",
"Microsoft.CSharp": "4.0.0-beta-22816"
}
}
Add using System.IO; to your usings section.
File class is located in System.IO namespace.
Alternatively (if it is the only place in your code where you're using some type from System.IO) you can use fully qualified name of File like:
var v = System.IO.File.ReadLines("dictionary.txt");
But in the case when you need to access objects from some namespace multiple times in your code, it is better to inculde that namespace in usings.
You need to include System.IO add using System.IO next to other usings.
Add a using statement:
using System.IO
I'm working .Net Core in vs2017 and I have a similar problem.
To solve this problem you should change the target framework and install System.IO.FileSystem.
Using the following methods:
Right click the project and select properties.
in Application Tab and Target Framework section change to .NetStandard1.6
Then, To install System.IO.FileSystem, run the following command in the Package Manager Console
Install-Package System.IO.FileSystem -Version 4.3.0
1.In here first we need to create the object like this.
OpenFileDialog ofd = new OpenFileDialog();
2.Then you need to add this top of your code
using System.IO;
3.Finally you can change your code like this
OpenFileDialog.Title -----> ofd.Title
OpenFileDialog.Filter -----> ofd.Filter

PostSharp Multicast not working in Outlook plugin code

I am using PostSharp in an Outlook Plugin app. If I add the following attribute to a class in my project it logs properly:
namespace Foo.Bar
{
[Log(AttributeTargetMemberAttributes = MulticastAttributes.Public)]
public class FooBar {...}
}
What I really want to do is log everything in the Foo.* namespace. I tried using the addin in VS which created a globalaspects.cs and updated my project.pssln file. At this point it wont build with the following error msg:
.dll uses non-licensed features (PostSharp Professional). Please enter a valid license key.
I figured it was recursing on itself so I added an AttributeExclude = true in the assembly line that was generated for me. It now looks like this (in globalaspects.cs):
[assembly: Log(AttributeExclude = true, AttributeTargetTypes = "Foo.*", AttributeTargetTypeAttributes = MulticastAttributes.Public, AttributeTargetMemberAttributes = MulticastAttributes.Public)]
No luck, it doesn't log anything this way. Any ideas why?
Additional info:
I am logging to log4net and I have other logging code that is working (it also works at both the class and method levels with PostSharp).
According to this page free license of PostSharp currently has limitation on number of methods on which [Log] attribute is applied. In my opinion, you have exceeded this number by applying the aspect on the whole namespace.
AttributeExclude means that the attribute will not be applied on declarations that satisfy conditions set in this attribute. It is basically set inclusion/exclusion operation. For example you can include Namespace1, exclude Namespace1.Namespace2 and again include Namespace1.Namespace2.Namespace3.
Therefore the following would be correct:
[assembly: Log(AttributeTargetTypes = "Foo.*",
AttributeTargetTypeAttributes = MulticastAttributes.Public,
AttributeTargetMemberAttributes = MulticastAttributes.Public)]
For more information about attribute multicasting, you can take a look on this article.
Note to reviewers: I'm one of developers working on PostSharp. I'm aware that this answer touches licensing, which is behind the red line and I have tried my best not to cross it too much.

Application.ProductVersion is not working

Application.ProductVersion is not showing the incremental version. can anybody help me how to perform this, using C# ?
You can have build and revision incremented for you but not major and minor.
Simply substitute
[assembly: AssemblyVersion("1.0.0.0")]
with
[assembly: AssemblyVersion("1.0.*")]
in the AssemblyInfo.cs
Have you tried grabbing the Assembly's version?
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Perhaps this is what you are looking for.
Also check out this other SO post - I think this is what you are looking for.
Automatically update version number
Below is a second link to a .Net add-in that automatically increments the:
Major
Minor
Build
Revision
http://testdox.wordpress.com/versionupdater/
I have found that it works well to simply display the date of the last build using the following wherever a product version is needed:
System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString("yyyy.MM.dd.HHMM")
Rather than attempting to get the version from something like the following:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
object[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false);
object attribute = null;
if (attributes.Length > 0)
{
attribute = attributes[0] as System.Reflection.AssemblyFileVersionAttribute;
}

Categories