Skip to content

Instantly share code, notes, and snippets.

View davkean's full-sized avatar

David Kean davkean

View GitHub Profile
Getting the following building with Visual Studio and Windows 10?
The "GenerateResource" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'file:///C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Tasks.v12.0\v4.0_12.0.0.0__b03f5f7f11d50a3a\Microsoft.Build.Tasks.v12.0.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Tasks.v12.0\v4.0_12.0.0.0__b03f5f7f11d50a3a\Microsoft.Build.Tasks.v12.0.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569
=== Logging started: 1/7/2015 15:53:20 ===
Action 15:53:20: ADMIN.
Action start 15:53:20: ADMIN.
Action 15:53:20: CostInitialize. Computing space requirements
Action start 15:53:20: CostInitialize.
Action ended 15:53:20: CostInitialize. Return value 1.
Action 15:53:20: FileCost. Computing space requirements
Action start 15:53:20: FileCost.
Action ended 15:53:20: FileCost. Return value 1.
Action 15:53:20: CostFinalize. Computing space requirements
@davkean
davkean / gist:13c551718b0b6d6850de
Created August 22, 2014 06:06
"Contract breaking" exceptions
You do not want to derive from InvalidOperationException. It and ArgumentException (and derivatives) are considered “contract breaking” exceptions.
Contract breaking exceptions should only be thrown to indicate that the caller has a bug. I pretend that every time I go to throw these exceptions that the process will be torn down immediately. If I’m okay with that, then I throw it, if not, then I should be throwing a different exception type.
Examples of contract breaks:
- You passed me index that was greater or equal to the number elements in the collection (returned by Count property)
- You passed me null, when I need a non-null value
- You passed me an empty string, when I need a non-empty string
- You called Start, but you’ve not set the ExecutablePath property.
@davkean
davkean / gist:986d8ac6cd65f585e442
Created August 20, 2014 16:59
Leaking enumerable
DirectoryInfo info = new DirectoryInfo(@"C:\Temp");
IEnumerable<FileInfo> files = info.EnumerateFiles("*.txt")
.Where(f => f.CreationTimeUtc > lastWeek);
foreach (FileInfo file in files)
{
} // With your proposal, where does Dispose get called on the strong-typed enumerable returend by EnumerateFiles?