Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reference Newtonsoft.Json.dll #18

Closed
mwpowellhtx opened this issue Nov 2, 2015 · 3 comments
Closed

How to reference Newtonsoft.Json.dll #18

mwpowellhtx opened this issue Nov 2, 2015 · 3 comments
Labels

Comments

@mwpowellhtx
Copy link

Hello I am trying to work with Json.NET via a T4 template and am having some difficulty. AFAIK, I reference the required assemblies that Json.NET wants, but am still receiving the error:

I have included the SolutionDir as an ItemGroup T4ParameterValue, I think that's correctly in the csproj file, but I could be wrong about that.

  <ItemGroup>
    <T4ParameterValues Include="SolutionDir">
      <Value>$(SolutionDir)</Value>
    </T4ParameterValues>
  </ItemGroup>

My template and error are below. The template is really simple now, bit it may become more elaborate. Basically, I want to specify the enumerated bits as Json collections, and have the boilerplate stuff taken care of by the template.

<#@ template debug="true" language="C#" hostspecific="true" #>
<#@ output extension="cs" #>
<#@ assembly name="System" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Numerics" #>
<#@ assembly name="System.Runtime.Serialization" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ assembly name="$(SolutionDir)tools\Json.NET\Bin\Net45\Newtonsoft.JSON.dll" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="Newtonsoft.Json" #>
namespace Football.Models.Enumerations
{
<# var name = "TestEnum"; #>
    using Domain;

    public partial class <#= name #> : Enumeration<<#= name #>>
    {
        private string TestMe = "<#= "this is a test" #>";

        private <#= name #>()
            : base(0)
        {
        }
    }
}
Error   105 There was a problem loading the assembly 'D:\Source\Kingdom Software\FootballSimulator\Working\src\tools\Json.NET\Bin\Net45\Newtonsoft.JSON.dll' The following Exception was thrown:
System.IO.FileLoadException: Could not load file or assembly 'file:///D:\Source\Kingdom Software\FootballSimulator\Working\src\tools\Json.NET\Bin\Net45\Newtonsoft.JSON.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///D:\Source\Kingdom Software\FootballSimulator\Working\src\tools\Json.NET\Bin\Net45\Newtonsoft.JSON.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 for more information.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.AttemptAssemblyLoad(String assemblyName)

        1   1   
@mwpowellhtx
Copy link
Author

For now I've gone a similar path as others have apparently gone, using RestSharp for the time being. I don't need the "REST"-fulness, or the Web or other bits, per se, but the references to RestSharp itself appear to be kosher with T4 at any rate.

@mwpowellhtx
Copy link
Author

Now I am realizing RestSharp really isn't built with a good, standalone Json serializer. In fact, it seems to want the whole Http Response mumbo jumbo. I don't want that, I just want the Json serialization. So, back to Newtonsoft. Why does that not work with T4?

@mwpowellhtx
Copy link
Author

Well, I decided to run with an Xml based approach. This seems much more amenable to the environment. Normally, I like Xml with its verbosity, except in this case where I want to drive some configuration, I'd rather aim for a more terse style protocol like Json. But Xml will definitely work in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants