EntityFramework force the update of an object

June 3rd, 2016 No comments

The Problem

You are trying to save some changes to an object.
Your code looks like the following:

But the changes are not being saved

The Solution

Entity framework is not aware that the job object has been changed so you need to tell it, by adding line 8.

Categories: c# Tags:

Windows 10 – KB3147458 – Windows update failure – 0x80070003 – ERROR_PATH_NOT_FOUND – FIXED!!

April 26th, 2016 2 comments

The Problem

I have numerous windows 10 machines and my desktop PC has started failing to apply the windows updates.

These two windows updates failed to install

  • Cumulative Update for Windows 10 Version 1511 for x64-based Systems (KB3140743)
  • Cumulative Update for Windows 10 Version 1511 for x64-based Systems (KB3147458)

Note: because of these issues I have set my windows update to notify and let me choose when to download and install

Setup Windows Update via Group Policy

The Symptoms

  • You are told there is a new update and you let it download and install.
  • Once completed you are asked if you wish to restart, so click restart
  • You are told that it is getting ready to install updates
  • In my case it gets to 3% and then reboots
  • Next it gives a message, “Cannot complete install. Undoing changes”
  • The computer reboots again
  • On login, you are told some udpates were unsuccessful

The Issue

In my particular instance this fixed the issue.

I first went and viewed the log file: C:\Windows\Logs\CBS\CBS.log
Depending on how long it has been since the error occured you may need to look for a file called “CbsPersist_20160425131704.log” where the number is the date/time of when the log file was created.

Open the file and search for “0x80070003 – ERROR_PATH_NOT_FOUND”

I found mine is a section as follows:

The issue is that one or more of the 16 drivers it is attempting to update has failed to be installed with a Path Not found error, but which one/s?

To find the details of the erroring driver update go to this file: c:\windows\Inf\setupapi.dev.log

Open this file and search for “Exit status: FAILURE”

I found the following, item of interest:

As you can see it is saying path not found in the FileRepository folder.
So I went looking and its right, I had no “capimg.inf_amd64_5a4379f63bea786c” folder!

The fix

In my case I have many other healthy windows 10 machines so I went and looked and sure enough they had the missing folder.

So I firstly copied the folder onto a usb key from the healthy machine.

There is a security issue with the FileRepository folder in that you will have no permissions on this folder.
To copy the “capimg.inf_amd64_5a4379f63bea786c” folder into the FileRepository directory you will need to go into the Advanced security and take ownership first. I am an admin on my PC, so I changed ownership to the Administrators group and then gave administrators full persmissions.

Once that is done you should be able to copy the missing folder into the FileRepository directory.

Next try to apply the update again and in my case it worked.

Windows10Update Success

Categories: Uncategorized, Windows Forms Tags:

Tricks to setting up WCF Service hosted on IIS

February 17th, 2016 No comments

The following is a short checklist of items to consider when trying to deploy a WCF Service to an IIS server.

These instructions are for a windows server box

  1. Ensure that you have the required level of .Net installed first
  2. Install the following roles – Application Server / Web Server and choose all the default options when prompted
  3. Check the ISAPI and CGI Restrictions and ensure .net framework 4.0.3 is installed and set to allowed
  4. If not you need to open a cmd window and go to c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ and run “aspnet_regiis -i”
  5. My service writes to a log file. Make sure the user that runs the application pool for the website has write access to the folder where the log file will be written

If you need to set up HTTPS then do the following

  1. In IIS Manager on the entire server double-click Server Certificates
  2. Create Self Signed Certificate, give it a name
  3. Create a https binding on a port
Categories: Uncategorized Tags:

X509Certificate object c# performance and memory issues alternative – fixed

February 17th, 2016 1 comment

The Problem

For my PatchCleaner product I needed the ability to read the digital certificate off a file, like can be seen on the following tab on the file properties window

msi

I want to read the digital certificate and obtain the contents of the “Subject” Field that is a string formated similarly to an Active Directory OU path.

CN=Microsoft Corporation, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

The Issue

I originally used the X509Certificate and X509ertificate2 objects like so:

 var cert1 = new X509Certificate(_file);
 var cert2 = X509Certificate2.CreateFromSignedFile(_file);

Both of these worked but I noticed that when accessing the certificate on a large file (200+ Mb):

  1. It was very slow
  2. It seemed to use alot of memory

In fact on closer investigation it appears the X509Certificate reads the entire object into memory! I had a file of 800Mb that I opened with X509Certificate2.CreateFromSignedFile(_file), and the memory usage on my application increased by the same 800Mb before releasing once I had read the value!! Not cool!!

The Solution

 
Performance

This image shows a test application that attempts to read a 294mb patch file in 3 different ways, with a 1 sec sleep between calls:

  1. T1 – read the digital certificate by the X509 Certificate
  2. T2 – read the certificate via WinCrypt all content
  3. T3 – my soltuion via WinCrypt with just PK7 content

You can clearly see two large memory spikes for test 1 and 2, but test 3 doesn’t even register.

Below is a full c# code sample.

I based my solution on the following stack overflow article

Get timestamp from Authenticode Signed files in .NET

References

The only extra class you need to import is:

  • System.Secuirty

WinCrypt

This is a copy paste from the stack overflow article:

CertificateHelper

This is my static class that implements two method calls.

  1. GetDigitalCertificateSlow() -This is the version behind T2 above
  2. GetDigitalCertificate() – this is the one you want

These methods were based on the IsTimestamp code in the StackOverflow article, but I have manage to tweak slightly to get superior performance.

Categories: Uncategorized Tags:

Running WCF Service as both HTTP and HTTPS

February 16th, 2016 No comments

When trying to configure a WCF service to run as both a HTTP and HTTPS endpoint there are some differences to consider:

  1. HTTP uses SOAP 1.1
  2. HTTPS uses SOAP 1.2

This can cause issues with how your XML packets need to be generated with different SOAP Headers.

SSL Config

On the IIS Manager under the website there is a tile titled “SSL Settings”.
To run both HTTP and HTTPS ensure “Require SSL” is unticked

Web Config

If you want to allow people to generate a .wsdl file do not forget to set this in the web config in the service behaviours

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
Categories: Uncategorized Tags:

citrix receiver disable add account popup on startup

February 16th, 2016 3 comments

The problem

I recently installed CitrixReceiver 4.4 for windows (on 2 windows 10 pc’s) and now on start up I am always being asked to “Add Account”

The Solution

The solution that worked for me was from the Citrix website

How to Suppress the Add Account Window in Citrix Receiver for Windows

After reading this I found the solution that worked on my x64 bit windows 10, (so I assume will work on 32 bit) was to run this registry entry

  1. Create a text file
  2. Copy/Past the text into it
  3. Save
  4. change the file extension to .reg
  5. Double click and follow the prompts
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Citrix]
"EnableX1FTU"=dword:00000000

The next time you start, no more Add Account window.

Categories: Uncategorized Tags:

SQL Server Script user with SID

September 18th, 2015 No comments

The Problem

When you move sql logins around servers the logins are created with an SID that uniquely identifies the login.

Assume you setup two logins manually, one on your production server and one on your dev server.

When you restore your prod database to development your Login will be “disconnected” from the restored database and the SID of the “User” in the restored production database does not match the SID of the Login on your dev box.

The Solution

Create your login specifying the SID.
The easiest way is to let SQL set and SID and then read it off the DB and use it in your new login creation script
This script should do it

Use master
GO

-- Step 1 - Create Login
IF  EXISTS (SELECT * FROM sys.server_principals WHERE name = N'usr_website')
DROP LOGIN [usr_website]
GO

CREATE LOGIN [usr_website] WITH PASSWORD = 'password:-)'
GO

-- Step 2 - Get SID
Declare @name nvarchar(254)

set @name = 'usr_website'

SELECT 
	[sid]
	,[status]
	,[name]
	,[dbname]
	,[language]
	,[denylogin]
	,[hasaccess]
	,[isntname]
	,[isntgroup]
	,[isntuser]
	,[sysadmin]
	,[securityadmin]
	,[serveradmin]
	,[setupadmin]
	,[processadmin]
	,[diskadmin]
	,[dbcreator]
	,[bulkadmin]
	,[loginname]
FROM [msdb].[sys].[syslogins]
where name = @name or @name is null

-- Step 3 - Create Login with SID
IF  EXISTS (SELECT * FROM sys.server_principals WHERE name = N'usr_website')
DROP LOGIN [usr_website]
GO

CREATE LOGIN [usr_website] WITH PASSWORD = 'password:-)', SID = 0x346837D1EC9C484C91A3B46D7EC7EABF
GO

Categories: SQL Server, T-SQL Tags:

T-SQL Drop temp table if it exists

September 9th, 2015 No comments

The Problem

I often work in SQL Server with temp tables and they can be a pain when developing as you may have code like

Create Table #tblTemp( Id int , Value nvarchar(32))

Insert Into #tblTemp
select Id, Value from SomeOtherTableAndLotsOfJoins

--Drop Table #tblTemp

You comment out the drop as you want to check the results and do some testing but next time you want to run the script you have to remember to call the “Drop Table”

The Solution

Put this at the top of your script

if exists(SELECT * FROM tempdb.dbo.sysobjects WHERE ID = OBJECT_ID(N'tempdb..#tblTemp'))
begin
	drop table #tblTemp;
end
Categories: T-SQL Tags:

LANTorrent seed you torrents from NAS without corruption

June 18th, 2015 No comments

The Scenario

I have been a long time user of uTorrent. I run it on my laptop that has limited storage, so if you want to keep seeding you have to relocate your downloaded files to an external drive. I use a wifi connected NAS type storage.

The problem

If uTorrent starts whilst you are offline, your entire seeding collection will be corrupted and it can take many hours, even days to recover.

The solution

LANTorrent

LANTorrent

>> DOWNLOAD FOR FREE HERE <<

LANTorrent is a wrapper for you existing torrent application that adds a layer of protection to stop you corrupting your torrent setup, and recovering when it does.

Features

Automatic startup 

You can set it so LANTorrent will start your preferred Torrent application when it starts. Combine that with setting LANTorrent to starts when windows starts, you can now have LANTorrent control the starting of your app.

Startup Protection

If you start your torrent application when off the network it will corrupt your configuration.

If you have LANTorrent set to start your torrent app, LANTorrent will look for your network drive. If the network drive is not accessible it assumes that you are disconnected and will not start your torrent application. This will stop you from accidentally destroying your seeding library.

Backup

LANTorrent can backup your torrent configuration, in the following ways:

  1. On startup
  2. On Close
  3. At predefined intervals

You can choose how many backups you wish to retain.

Restore

If you happen to corrupt your configuration, just choose a backup and click restore and you are back up and running.

Shutdown

LANTorrent monitors the torrent application and will close itself (and perform an on close backup if set), when it detects that the torrent application has closed.

Compatibility

Runs on Windows and requires .Net 4.5

Supported Torrent Clients

  1. uTorrent
  2. Vuze
  3. BitTorrent
  4. BitLord
  5. Deluge
  6. qBittorent
  7. tixati

>> DOWNLOAD FOR FREE HERE <<

Categories: Free Software Tags:

Clean the Windows Installer Folder

June 1st, 2015 3 comments

Problem

The c:\Windows\Installer folder contains windows .msi installers and .msp patch files that are used when installing and updating software on your windows computer.

Over time as more and more programs are patched the size of this directory gets very large and some of the files are actually orphaned and no longer required on your system.

The problem is you cannot just delete the entire directory as these files are used when upgrading or uninstalling your software. What you need to do is only delete those files that are not in use any more

Solution

Patch Cleaner

This is a simple piece of software that will clean your windows installer folder in one easy click.

PatchCleaner

PatchCleaner

If you are unsure of the program just use the move function to move the detected orphaned patches off onto an external drive. If the program has done something wrong you can just copy them back.

This software is 100% free. >> Download Here <<

Categories: Free Software Tags: