Sometimes, you want to know if your assembly is a Debug or Release build – like if you’re outputting assembly information for diagnostic purposes. But how do you know? Continue reading
Category Archives: Languages
Clearing the CA0068 Error in Code Analysis
This error was appearing in the code analysis for one of my SharePoint projects. It reads:
Warning 1 CA0068 : Debug information could not be found for target assembly ‘Something.exe’. For best analysis results, include the .pdb file with debug information for ‘Something.exe’ in the same directory as the target assembly.
Annoyingly, it didn’t seem to allow you to suppress it, and I was doing a Release build – so I didn’t expect to have a .pdb file. Continue reading
Attaching Visual Studio 2010 to Outlook 2010 plugin for Debugging
I was trying to attach a debugger to an Outlook plugin I was working on. It was originally written for Outlook 2003, but has been progressively upgraded to 2010. However, I couldn’t breakpoint my code, or rather, the breakpoints weren’t being hit.
Found the answer on Stack Overflow:
So it turns out that Outlook doesn’t load the CLR on startup (it must be loaded shortly thereafter when it becomes necessary), which apparently confuses the VS debugger and causes it to only debug native code. To force it to load the CLR immediately, create an OUTLOOK.EXE.config file in the same folder with:
<configuration> <startup> <supportedRuntime version="v2.0.50727"/> </startup></configuration>
which is from this blog post. Then, even when VS starts attached, it will debug CLR code
Editing a XAML build process
So, we’ve been working on putting our SharePoint solutions through a proper build process in Team Foundation Server 2010 (TFS), and I hit a bit of a snag.
I had been given a build definition that had a build process – a Workflow Foundation workflow – that I wanted to alter. The problem was that while I had the XAML file for that workflow, and the DLL that defined some custom code activities that the process used, I didn’t have a full Visual Studio project for it. No problem, I thought, I’ll just open the XAML up in Visual Studio and edit it.
Wrong.
Error: ‘b’ is null or not an object
This error has caused me so much pain when trying to use SharePoint’s JavaScript client-side object model (CSOM), so, in case I have it again:
- Check that the function exists.
- Check that the function is named correctly.
- Make sure that you’re not using “this” in the call to createDelegate, as detailed here.
- Right:
Function.createDelegate(this, onSuccessMethod) - Wrong:
Function.createDelegate(this, this.onSuccessMethod)
I don’t know why this difference should cause this error, but I’ve proved it true.
- Right:
If you know of other causes of this error, let me know, I’ll add it to the list. I love the experience of debugging JavaScript…
Further notes on SmartAssembly Obfuscation
Some further notes on things I’ve learnt using SmartAssembly on some of our products.
- Constants do not get obfuscated. Use static readonly variables in their place if the constant contains sensitive information.
- Run Reflector (or reflection tool of your choice) against your assembly after obfuscation, to check what is visible. Then go back and make the bits you accidentally left public internal or private.
- Make as many classes and methods as you can Internal
- Do read the instructions on the attributes you can apply to control obfuscation.
- Do use Pruning if you want to remove parameter names for methods. That can leak a lot of information about what a class is doing.
Obfuscation, Code Analysis, and Check-In policies
As mentioned before, we’ve started to use SmartAssembly to obfuscate some of our products. We also use Team Foundation Server (TFS) as source control and build server. Using obfuscation with code analysis caused some issues, which were compounded by our check-in policies. Continue reading
Adding SmartAssembly obfuscation to a Visual Studio Project
We’ve started to use SmartAssembly to obfuscate the code for some of the SharePoint products that we’ve been working on, and I’d had a few problems with it. Continue reading
Disable Output Escaping in XSL
Really, just a reminder for myself, but if you work with SharePoint long enough you’re bound to end up using something like the Content Query Web Part or a Data View Web Part to aggregate and output a rich text source – but all your HTML gets escaped, so it appears content on the page.
The command you want is DisableOutputEscaping:
<xsl:value-of select="somevalue" disable-output-escaping="yes" />
This will cause the HTML to be output unescaped – i.e. as HTML.
Side note: Sometimes people want things like the CQWP to show the first part of the content as a ‘summary’. This trucating content to display in the CQWP or DVWP is difficult; either a) you risk having unfinished tags in the HTML you do emit, or b) you have to strip out all HTML, which can ruin your formatting. a) is a particular problem, as unfinished <table> tags can cause all sorts of weirdness on page.
My preferred option is to have a additional ‘summary text’ box that accepts plain text, and have the author generate the summary manually. That way we avoid outputting HTML like that entirely.
Random things I learnt doing a code review
Code Reviews are interesting – both sides can learn something, and the one I’ve just done taught me a few things… Continue reading
