Dotfuscator removing Windows Phone 7 language support? - windows-phone-7

The XNA game that I am working on for WP7 supports multiple languages. However, something seems to be happening during the obfuscation process which seems to cause the language to always be set to English (the default language, in this case), at least according to the Resource class.
For example, each resource pack contains the following definition:
RESOURCE_IDX -> #
And each resource pack is given a different #. In an un-obfuscated build, the correct index is pulled out based on the device's current language. However once obfuscation occurs, the Resource class automatically selects the value associated with English even if the device is set to Spanish.
Is there a setting that I'm missing in the obfuscation process that is causing this?

It would appear that my issue was related to the renaming of the Resource class. That class is simply a set of auto-generated getters based on the contents of the resource packs. Somehow, subjecting that class to renaming during obfuscation caused the improper value to be returned (I won't speculate on why).
Once I prevented that class from being renamed, the rest of the application worked as expected.

Related

Dotfuscator Seems Not Adhering To Renaming Exclusion RegEx

We have decided to use the Dotfuscator to obfuscate our code. Ours is a Windows Phone application and we are using Dotfuscator Windows Phone Edition Version 4.9.7000.29303. We learnt that System.Reflection.ObfuscationAttribute class is not available in Silverlight, so it is not possible to use exclusion attributes on some types we need to exclude. We are now planning to use Rename>Exclude tab in dotfuscator and exclude types with some specific suffixes. Before implementation we created a trial project and tested obfuscation on it. We found in our testing that the output is not adhering to execution rules. Though the preview window is showing expected result but output still includes those types which should have been excluded. Please see the screen shot of the Dotfuscator window below. Preview window on the left hand side of the arrow is correctly displaying the shaded type which would be excluded from obfuscation, but on the right hand side of the arrow, output of the same still obfuscated those types. What is happening?
I don't entirely understand what you're trying to accomplish with the regular expression, but as far as using attributes to control obfuscation, there is a library you can include.
The library to include is typically in
C:\Program Files(x86)\PreEmptive Solutions\Dotfuscator (version and edition)\Attributes\Windows Phone\PreEmptive.ObfuscationAttributes.dll
Here is an example on how to exclude something from renaming for instance:
[Obfuscation(Feature = "renaming", Exclude = true)]
public int Foo{get;set;}
You can find more details about it controlling obfuscation with attributes at this link and the general users guide is available here
If you want to go the regex route instead, you can also look at the documentation for creating custom rules. You'll have to provide a bit more info for me to understand what you're trying to do for me to be able to help though. Given your screenshot, everything appears to be what I'd expect.

C++ Builder 2009 - i18n - Quick Reports Exception - Class TQRPDFFilter not Found - When Change Format

Using Win7, C++ Builder 2009 I have a project that I am able to compile and run without any issues when my region and language format is set to "English (United States)".
When I change the format to "Italian (Italy)", my program compiles then I get an exception that "Project .exe raised exception class EClassNotFound with message 'Class TQRPDFFilter not found'."
Nothing else changes in the program or paths, just the system change and I get this exception. I checked both the include and lib paths and they are setup correctly.
Its been a while since I asked this question. I'm following up, just as a reference. I believe the issue was based on the import paths our projects use. We have a "common" set of code which is shared between some projects. The common source has references to TQRPDFFilter where the specific project does not. By changing the path order, putting common at the least priority, I got past my problem. This does not answer the question as far as why it was blowing up with the different language, but might give some insight to others on how to get past it, if they come across similar setups.

How to use neutral language in Windows Phone

I am facing the following issue:
I have translated my application into different languages using resx files. I want to use the same resx files in other apps as well.
For different apps, I should be able to change the default language (some apps will only be available in Spanish, others only in English, and others multilingual)
I figured I could just name the resources LanguageStrings.es.resx and LanguageStrings.en.resx, and use NeutralResourcesLanguageAttribute to set the default language of the app.
However, when there is no LanguageStrings.resx (invariant file) in the app, the application seems to break (MissingManifestResourceException). I thought the Resource Manager should use the setting in NeutralResourcesLanguageAttribute to find the correct resource (for example; fall back to Spanish) instead of looking for a neutral file.
Is my assumption correct and am I running into a platform bug? I have noticed that ResourceManager.GetNeutralResourcesLanguage doesn't returned the language defined using NeutralResourcesLanguageAttribute, but invariant culture instead
Without a invariant resource file (LanguageStrings.resx), the compiler won't pick it up. You should let the English resource file (Currently LanguageStrings.en.resx) be the invariant file, ie. without .en in the filename, and then set
[assembly: NeutralResourcesLanguage("en")]
All .NET applications work this way. It's not a unique "issue" to Windows Phone.
I believe if you specify your language as supported in the element in your csproj - you need to have the resx that you are trying to use in the supported culture. If you use the language that is supposedly supported and the resx is not there - you will get a MissingManifestResourceException. Neutral language will be picked up if the current language is not supported.

Additional/extended code analysis rules

I recently set up the static analysis in VS2010 for one of my hobby projects (and annotated all headers), and some of the suggestions it made helped track down a few annoying little bugs.
Seeing that, I've been curious as to whether there is a more extensive rule set around or if such things are available anywhere (I'm using the "Microsoft All Rules" at the moment).
Are there additional rule sets that I could use; if so, where? (Google didn't find any easily)
If not (or even if there are), is there a better set to use? (my project works with graphics mostly)
I have written about 8, and may be writing more soon, if any of these interest you let me know.
Team policy reminder/enforcers
warn on calls to forbidden methods
GC.Collect GC.AddMemoryPressure
Messagebox.Show
warn if inheriting directly from Windows.Forms or Windows.Control
warn if a control or form subclass constructor does not call InitializeComponent()
warn if a control property is not set per team standards
DialogBorderStyle must be fixed
error if you do not override certain virtual properties (legacy from vs2005 designer bug)
error if you have code that raises a NotImplementedException
warn if you don't have hungarian notation to name controls
warn if fields are not private
ensure a project does not call a Config value or index that does not exist.
Also some of the code is found here

Building a Visual Studio Package based on another one

I want to add my own project type based on IronStudio. So,
I downloaded the source for and compiled the latest version of IronPython, then
I created a new Visual Studio Package.
I added the Templates\Projects\MyProject folders, and added a file to it, and set its property "Include in VSIX" to true.
Then modified the main Package class to be derived from IronStudio's PythonProjectPackage instead, and set the ProvideProjectFactory property:
[ProvideProjectFactory(
typeof(PythonProjectFactory),
"Django Project",
"Django Project Files (*.myproj);*.myproj",
"myproj", "myproj",
#"Templates\Projects\MyProject",
LanguageVsTemplate="MyProject")]
public sealed class MyPackage : PythonProjectPackage
And ran it. But MyProject isn't showing up in the project templates. Why not?
The generated .pkgdef file looks like this:
[$RootKey$\InstalledProducts\VSPackage3Package]
#="#110"
"Package"="{5cd7435c-7461-459f-80bc-c0c79e9d462f}"
"PID"="1.0"
"ProductDetails"="#112"
"LogoID"="#400"
[$RootKey$\Packages\{5cd7435c-7461-459f-80bc-c0c79e9d462f}]
#="Microsoft.VSPackage3.VSPackage3Package, VSPackage3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a4f1577d825253f8"
"InprocServer32"="$WinDir$\SYSTEM32\MSCOREE.DLL"
"Class"="Microsoft.VSPackage3.VSPackage3Package"
"CodeBase"="$PackageFolder$\VSPackage3.dll"
[$RootKey$\Editors\{888888c4-36f9-4453-90aa-29fa4d2e5706}]
"Package"="{5cd7435c-7461-459f-80bc-c0c79e9d462f}"
[$RootKey$\Editors\{888888c4-36f9-4453-90aa-29fa4d2e5706}\Extensions]
"py"=dword:00000020
[$RootKey$\Editors\{888888c4-36f9-4453-90aa-29fa4d2e5706}\LogicalViews]
"{7651a701-06e5-11d1-8ebd-00a0c90f26ea}"=""
[$RootKey$\Editors\{888888c4-36f9-4453-90aa-29fa4d2e5706}\LogicalViews]
"{7651a702-06e5-11d1-8ebd-00a0c90f26ea}"=""
[$RootKey$\Editors\{888888c4-36f9-4453-90aa-29fa4d2e5706}\LogicalViews]
"{7651a703-06e5-11d1-8ebd-00a0c90f26ea}"=""
[$RootKey$\CLSID\{888888fd-3c4a-40da-aefb-5ac10f5e8b30}]
#="Microsoft.IronPythonTools.Project.PythonGeneralPropertyPage"
"InprocServer32"="$WinDir$\SYSTEM32\MSCOREE.DLL"
"Class"="Microsoft.IronPythonTools.Project.PythonGeneralPropertyPage"
"CodeBase"="$PackageFolder$\VSPackage3.dll"
"ThreadingModel"="Both"
[$RootKey$\Projects\{888888a0-9f3d-457c-b088-3a5042f75d52}]
#="PythonProjectFactory"
"DisplayName"="My Project"
"DisplayProjectFileExtensions"="My Project Files (*.myproj);*.myproj"
"Package"="{5cd7435c-7461-459f-80bc-c0c79e9d462f}"
"DefaultProjectExtension"="myproj"
"PossibleProjectExtensions"="myproj"
"ProjectTemplatesDir"="$PackageFolder$\Templates\Projects\MyProject"
"Language(VsTemplate)"="MyProject"
[$RootKey$\NewProjectTemplates\TemplateDirs\{5cd7435c-7461-459f-80bc-c0c79e9d462f}\/1]
#="My Project"
"SortPriority"=dword:00000064
"TemplatesDir"="$PackageFolder$\Templates\Projects\MyProject"
[$RootKey$\Projects\{888888a0-9f3d-457c-b088-3a5042f75d52}]
#="PythonProjectFactory"
"DisplayName"="IronPython"
"DisplayProjectFileExtensions"="IronPython Project Files (*.pyproj);*.pyproj"
"Package"="{5cd7435c-7461-459f-80bc-c0c79e9d462f}"
"DefaultProjectExtension"="pyproj"
"PossibleProjectExtensions"="pyproj"
"ProjectTemplatesDir"="$PackageFolder$\.\NullPath"
"Language(VsTemplate)"="IronPython"
[$RootKey$\NewProjectTemplates\TemplateDirs\{5cd7435c-7461-459f-80bc-c0c79e9d462f}\/1]
#="IronPython"
"SortPriority"=dword:00000064
"TemplatesDir"="$PackageFolder$\.\NullPath"
[$RootKey$\Services\{b98e41c4-581e-3532-beee-06829b683d39}]
#="{5cd7435c-7461-459f-80bc-c0c79e9d462f}"
"Name"="IPythonStarter"
I just want to get the bare bones up and running so I can start overriding some functionality (like the Add New Item dialog).
Update:
Reading my initial analysis once again increases my impression that some of the required components are missing (e.g. a dedicated ProjectFactory) and/or wired up incorrectly - from the MSDN documentation of the ProvideProjectFactoryAttribute Class:
ProvideProjectFactoryAttribute declares that a package provides a project factory.
And further:
If a VSPackage declares that it provides a project factory, it should create the factory and offer it to Visual Studio in the Initialize method of the Package-derived class.
You package is declaring to provide PythonProjectFactory, but (likely) doesn't offer it to VS, rather it is offered by the IronPython package. In turn you are providing arguments within the ProvideProjectFactory attribute list which PythonProjectFactory won't know about when asked for by VS.
Consequently you should at least provide a dedicated ProjectFactory yourself as per the walkthrough, wire up the classes accordingly and see how this turns out regarding the issues outlined below.
Initial analysis:
There appear to be several issues here at first sight - have you followed any tutorial on how to do this? In case, please note that some of those easily discoverable via search engines are outdated still. Either way I'd try working through and/or comparing your result with Walkthrough: Part 1 - Creating a Basic Project System from the MSDN documentation for VS 2010; please note that even this one is claimed to be outdated a bit according to the Community Content section on the bottom of the page.
Here is what I'd look into myself given the code you present, comparing with the walkthrough on the fly for more insights:
You realized already that the duplicate fragment starting with the GUID above PythonProjectFactory doesn't make sense - this is essentially trying to register two packages at once, which, even if allowed at all syntactically (which I doubt), can't possibly work like so due to both being registered with the same GUID [cross checking with the sample file in section Examining the Template Registration confirms this suspicion, as expected there is only one such fragment].
Please note that the GUID in question is the one identifying PythonProjectFactory (as per the respective source code), see below for more on this.
[Guid(PythonConstants.ProjectFactoryGuid)]
public class PythonProjectFactory : ProjectFactory {
Given .pkgdef is a generated file the next question is where this duplication/violation stems from. When two generated artifacts end up with the same GUID the respective definition in the sources is most likely messed up somehow, usually due to copy&paste duplication. Consequently you should verify whether {5cd7435c-7461-459f-80bc-c0c79e9d462f} is defined and referenced as intended, though here might be one or two other causes as well for this, see below.
A Package class needs to be identified by a GUID and the VS wizard generates some already in Guids.cs and references it accordingly on the class definition, however, the following is missing in your fragment [cross checking with the sample fragment in section To register the project template confirms this omission as well]:
[Guid(GuidList.guidMyPackagePkgString)]
public sealed class MyPackage : Package
Likewise it appears incorrect to derive MyPackage from PythonProjectPackage but reference PythonProjectFactory still rather than providing MyFactory as well (including a dedicated GUID), because the latter tells Visual Studio the location of your project template folder [see section Creating a Skeletal Project Factory]:
While it might well be possible to simply reuse all functionality from the base class PythonProjectFactory, inheriting is likely required simply because the factory must have a dedicated GUID too (as outlined in the walkthrough) in order to properly wire up the attribute specified data.
Likely unrelated, but still suspicious is that your two code blocks don't relate, as the Package class definition specifies Django Project Files (*.myproj);*.myproj, yet the result shows My Project Files (*.myproj);*.myproj.
Have you by chance mixed this from different builds or is this really a result of a clean one?
Good luck!
This stackoverflow posting might be helpful: VS2010: VSIX installation doesn't deploy item templates inside it
If this is not what you're looking for, try to see if you're missing something around the creation of custom project templates, I believe that's where the "missing link" is:
For VS 2008:
http://blogs.msdn.com/b/webdevelopertips/archive/2008/12/02/tip-32-did-you-know-how-to-easily-create-your-own-project-templates.aspx
For VS 2010:
http://blog.reybango.com/2010/09/21/how-to-create-html5-website-and-page-templates-for-visual-studio-2010/
and on MSDN:
http://msdn.microsoft.com/en-us/library/s365byhx.aspx
and here is how to create a project
template manually:
http://msdn.microsoft.com/en-us/library/ms185291.aspx
and here is how to create a new item template in VS 2010: http://msdn.microsoft.com/en-us/library/ms247113.aspx
Hope this helps
$PackageFolder$.\NullPath may have something to do with it.

Resources