Fixing the “Could not load file or assembly … or one of its dependencies” error

Visual Studio logo

This post describes how to fix the “Could not load file or assembly ‘<assemblyname>’ or one of its dependencies. An attempt was made to load a program with an incorrect format.” error. 

Problem

Especially while installing a new dev machine, and building your project for the first time, you may end up getting the following exception:

No fear, though, as this is usually easily fixed. In quite a few cases, it’s simply a mismatch between architectures and easily changed.

Continue reading

Getting Connect-MsolService (and other SharePoint Online cmdlets) to work

Connect-MsolService

In this post, I’ll try to archive everything you need to download and install to get commandlets like Connect-MsolService working. I’ve had to do it a couple of times when changing laptops, so it’s good to document them somewhere 🙂

Required installations:

  1. Microsoft Online Services Sign-In Assistant for IT Professionals RTW
    1. https://www.microsoft.com/en-us/download/details.aspx?id=28177
  2. SharePoint Online Management Shell
    1. https://www.microsoft.com/en-us/download/details.aspx?id=35588
  3. Windows Azure Active Directory Module for Windows PowerShell (v1)
    1. http://connect.microsoft.com/site1164/Downloads/DownloadDetails.aspx?DownloadID=59185

Now, to run cmdlets like “Connect-MsolService”, just start SharePoint Online Management Shell (or PowerShell).

If you also need Azure Remote Management (AzureRM) cmdlets, run this in an elevated PowerShell:

Continue reading

Remove-SPODeletedSite – Actually removing a SharePoint Online Site Collection

Delete site collection

This post describes the actual, working and fast process of removing a site collection in SharePoint Online using the Remove-SPODeletedSite commandlet in SharePoint Online Management Shell (a flavor of PowerShell).

Description

Sometimes you need to get rid of a site collection you’ve created in SharePoint Online. The most typical example perhap being removing the team site created for a group of people working together. That’s pretty simple and there are a few ways of doing that – namely, deleting the site from Site Settings or removing the site collection from SharePoint Administration. However, sometimes you need to recreate a new site using the same url as the one you removed – and that’s not going to be possible.

"Delete this site" on SharePoint Online

“Delete this site” on SharePoint Online

Delete site collection

Delete site collection on SharePoint Administration

Why is that, you ask?

Well, after you remove the site collection, it actually goes to the recycle bin. The bad thing is, that this recycle bin is NOT accessible using web browser, but only by PowerShell. SharePoint Online still reservers that url for the site, though, so you can’t create a new one with the same url!

Continue reading

Applying Entity Framework’s Code-First Migrations against a Database in Azure by running Update-Database

This post describes how to run Entity Framework’s code-first migrations against a database located in the Windows Azure. This is done by running Update-Database commandlet with suitable switches, see below.

The problem and symptoms

Okay, so you’re developing your MVC+EF cool web app with a database in Azure, and you’re using code-first migrations. Cool! What’s nice with code-first-migrations is the fact they are run automatically even in the cloud the next time your app is running (as long as you publish your app with that little box ticked – something like in the screen capture below). But wait – what if there are conflicts – what kind of errors are you going to get?

 

Azure Web Publish

Azure Web Publish

Not very useful ones, I’m afraid, and it’s a pain navigating the Azure portal to fetch the log files. At some point – for me, it wasn’t the first time I ran the web app, but the phase when I was logging in – you’ll be getting the error the migrator internally throws. That might be enough to point you to the right direction, and maybe you’ll be able to figure out what’s wrong! But if that’s not the case, here’s the way to run Update-Database against your Azure Database!

Continue reading

Exception of type ‘System.OutOfMemoryException’ was thrown.

IIS8

This post describes one of the more no-brainerish ways of fixing a ‘System.OutOfMemoryException’ exceptions being thrown in your MVC ASP.Net application using Entity Framework.

Problem

While developing a web project, for example ASP.NET MVC with EF, sometimes when handling a lot of data or complex entities on your dev machine, you encounter this error:

Reason

By default, Visual Studio uses 32-bit version of IIS Express for your deployments. In case you know what you’re doing, it’s safe and easy to change this, though.

Continue reading

Solving Azure Web Application’s first load perfomance issues

Microsoft Azure logo

Is your Azure Web Application suffering from absolutely horrible load times every time someone access it for the first time every 15 minutes or so? Mine was.

I was developing a web-based service using EF6 and ASP.NET MVC 5, where all the assets were hosted in the Azure. Even though the app was reasonably lightweight and usually responded very fast, the first time someone accessed it in a while it took 20-60 seconds to load AND sometimes even timeouted (especially with mobile clients). Load testing revealed only the what I already knew: initial load times were horrendous, but after that everything worked fine. I did eventually find the solution, though!

Continue reading

Solving the “Spatial types and functions are not available …” -problem

Spatial SQL types

This page describes mutiple ways on how to fix the exception ‘Spatial types and functions are not available for this provider because the assembly ‘Microsoft.SqlServer.Types’ version 10 or higher could not be found.‘ which comes up during debugging or publishing your program, app or service using DbGeography.

Symptoms

While running a console program or perhaps installing an ASP.NET MVC website on a machine, where SQL Server (apart from the one that comes with the Visual Studio) has not been installed, you may encounter the following error:

At least for me, this was baffling as that assembly was included in the project, and would compile and run flawlessly on other machines, just not on this one. I’m documenting here all the possible fixes to the issue I am aware of.

Problem / Reason

For me, the actual reason was that even though the DLL was loaded and included in the project as a nuget package, the actual native assemblies for this dll were not loaded to memory, as this needs to be done in the runtime. This issue was made worse by the fact that I first created this solution on a machine, where SQL Server was installed, so I was very much oblivious of the issue until it hit me on the face while trying to run my program on this particular machine, which did not have SQL Server.

Continue reading

Using PowerShell to set ULS logging level to “extra verbose” to catch all the events in the logs

Stock photo from pixabay.com

This blog post describes how set the SharePoint’s ULS level to “Extra Verbose” (VerboseEx) using PowerShell. This is not possible using the browser UI.

Description of the solution

By default, ULS logging is somewhat non-detailed, and a lot of data that could be used to debug issues is omitted. The UI cannot be used to set this level of logging – it is limited to verbose. In case you really, REALLY need to get all the data logged to ULS, you can use PowerShell to enable verboseex -level tracing, using the following command:

Beware, though: this will generate a lot of data, and it’s likely you won’t be able to do anything with the log files using notepad++ or similar tool, as a single file can be hundreds of megabytes, and handling that might get a little tricky.

You can always reset this setting to default (medium-level tracing) by running the following command:

 

More info about the trace levels:

Disabling anonymous access on a single site through PowerShell

Anonymous access in SharePoint 2013

This post is about managing Anonymous Access on a SharePoint site (SPWeb) using PowerShell commandlets. It’s often a lot more feasible and even easier than using the browser interface!

Description

Assume you have a site collection that’s published to the whole world. You’ll have anonymous access enabled at both web application and site collection -levels, and configured permissions at the root web -level. Now, let’s assume you want to disable anonymous access on a certain site deeper in the site structure. This way anonymous users could access your site at http://site.com and http://site.com/subsite, but not at http://site.com/subsite/deepsubsite. As an added bonus, that web would even be removed from the navigation for anonymous users (security trimming).

Solution(s)

Of course, you could do this through site permissions -page via browser (http://site.com/_layouts/15/user.aspx) by breaking permissions inheritance and disabling anonymous access, but there are multiple situations when this is not feasible – say, for example, that you already have a redirection for that certain url set in the IIS or gateway, and can’t access the page. Luckily, this can also be done with PowerShell.

 

This is a lot faster than through browser, right? 🙂 Just remember to use the right url for the web, SharePoint will find out the right zone for you!