Python for .NET "unable to find assembly" error

One reason can be Windows was not enabling it to load from "external sources". To fix this:

  • Right-click on the .dll
  • "Properties"
  • Under "General", click "Unblock"

Is DotNet4Class.dll built against .NET 4? I assume so based on the naming of the dll.

Note the issue here: http://sourceforge.net/tracker/?func=detail&aid=3293169&group_id=162464&atid=823891

clr.AddReference fails when assembly is built with .NET 4.0 - ID: 3293169

I'd read the solution, but essentially, you need to rebuild and recompile the python for .NET project under .NET 4.

I'll also mention that projects like this, that aren't actively developed and used by lots of people, generally have subtle idiosyncrasies that make knowledge of the platform essential to work around problems such as this. It sounds like you're trying to hack this solution in without understanding much about python or .NET which is always going to be fraught with problems.


Did you try clr.FindAssembly?

import clr
import sys
assemblydir = r"C:\pyfornet_test"
assemblypath = r"C:\pyfornet_test\DotNet4Class.dll"
sys.path.append(assemblydir)
clr.FindAssembly(assemblypath)

I don't know why it works, but this code works on my computer (Python 2.7, .NET4)


Try this (without extension .dll):

clr.AddReference(r"C:\pyfornet_test\DotNet4Class")