In the question: Idiomatic way to write .NET interop function I found the following code segment:
(import '(System.Net HttpWebRequest NetworkCredential)
'(System.IO StreamReader))
When I start a REPL and enter:
(import '(System.IO StreamReader))
all is OK. But when I enter:
(import '(System.Net HttpWebRequest))
(I don't need the NetworkCredential functionality) I get:
My.ns=> (import '(System.Net HttpWebRequest))
Bad type
NullReferenceException Object reference not set to an instance of an object. cl
ojure.lang.Util.NameForType (D:\work\clojure-clr-1.4.1-fix\Clojure\Clojure\Lib\U
til.cs:729)
Oh, and I have previously done:
My.ns=> (System.Reflection.Assembly/LoadWithPartialName "System.Net")
#<RuntimeAssembly System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b
03f5f7f11d50a3a>
So what else do I need to do? Thanks for any help.
This is a bug in 1.4. It comes from not properly handling a type being accessible from more than one assembly. In this case,
System.Net.HttpWebRequestis in theSystemassembly. Importing that class before you load theSystem.Netassembly works just fine. After you load theSystem.Netassembly,HttpWebRequestis accessible from two assemblies (thanks to aTypeForwardedToattribute inSystem.Net). In ClojureCLR 1.4.1, this is not handled properly.Solutions:
System.Netor do your import ofHttpWebRequestprior to doing so.