Options

DotNet DLL e NAV2009 R2

iperutilityiperutility Member Posts: 18
edited 2014-12-05 in NAV Three Tier
Hi guys,

I had did a DLL in c# and implemented in NAV 2009 R2, but when I had ran the form that used a global dot net variable "Dotnet DLL", NAV 2009 R2 got me an this error

"impossible to use the type of .NET Interop In the code for runtime"

Have you any idea? ](*,) ](*,) ](*,) ](*,)

this is my DLL

using System;
using System.Collections.Generic;
using System.Text;


namespace DemoAddIn
{
using System;

public class DemoAddIn
{
/// <summary>
/// Private field where the constructor stores the name of the
/// demo object.
/// </summary>
private readonly string demoName;

/// <summary>
/// Gets the private read only field demoName.
/// </summary>
public string DemoName { get { return demoName; } }

/// <summary>
/// Backing field for the property
/// </summary>
private string getSetProperty;

/// <summary>
/// Gets or sets a property using a backing field. Don’t return null values to AL
/// as this can give unpredictable results.
/// </summary>

public string GetSetProperty
{
get { return getSetProperty ?? String.Empty; }
set { getSetProperty = value; }
}

/// <summary>
/// Initializes a new instance of the DemoAddIn class and assign a value to the
/// demoName field.
/// </summary>
/// <param name="name">Name of the demo object.</param>
public DemoAddIn(string name)
{
demoName = name;
}

/// <summary>
/// Sample function that illustrate how to use function parameters and
/// return data.
/// </summary>
/// <param name="arg">Function parameter</param>
/// <returns>The function arguemnt value or the constant string Empty if the
/// parameter is null or empty.</returns>
public string FunctionWithArgument(string arg)
{
return String.IsNullOrEmpty(arg) ? "Empty" : arg;
}
}
}

this is my Codeunitusing System;
using System.Collections.Generic;
using System.Text;


namespace DemoAddIn
{
using System;

public class DemoAddIn
{
/// <summary>
/// Private field where the constructor stores the name of the
/// demo object.
/// </summary>
private readonly string demoName;

/// <summary>
/// Gets the private read only field demoName.
/// </summary>
public string DemoName { get { return demoName; } }

/// <summary>
/// Backing field for the property
/// </summary>
private string getSetProperty;

/// <summary>
/// Gets or sets a property using a backing field. Don’t return null values to AL
/// as this can give unpredictable results.
/// </summary>

public string GetSetProperty
{
get { return getSetProperty ?? String.Empty; }
set { getSetProperty = value; }
}

/// <summary>
/// Initializes a new instance of the DemoAddIn class and assign a value to the
/// demoName field.
/// </summary>
/// <param name="name">Name of the demo object.</param>
public DemoAddIn(string name)
{
demoName = name;
}

/// <summary>
/// Sample function that illustrate how to use function parameters and
/// return data.
/// </summary>
/// <param name="arg">Function parameter</param>
/// <returns>The function arguemnt value or the constant string Empty if the
/// parameter is null or empty.</returns>
public string FunctionWithArgument(string arg)
{
return String.IsNullOrEmpty(arg) ? "Empty" : arg;
}
}
}

this is my codeunit


Name DataType Subtype Length
demoAddIn DotNet 'ClassLibrarySGATE, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2682bd8dc3f2a56d'.DemoAddIn.DemoAddIn
demoString DotNet 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.String
textVar Text 1024

// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

// Create an instance of the DemoAddIn type. The constructor takes a string argument
// which is used to initialize an internal variable.
demoAddIn := demoAddIn.DemoAddIn('Input data');

// Use the property 'DemoName' to read the name set in the constructor.
MESSAGE('DemoAddIn contains %1', demoAddIn.DemoName);

// Test that the property ‘GetSetProperty’ contains an empty string
IF NOT demoString.IsNullOrEmpty(demoAddIn.GetSetProperty) THEN
ERROR('The uninitialized property should return an empty string');

// Use the property setter to assign an AL string to the internal CLR string variable.
demoAddIn.GetSetProperty := 'Value set with property';

// Read the property and see that the value has been set accordingly.
MESSAGE('DemoAddIn contains %1', demoAddIn.GetSetProperty);

// Call a function in the AddIn that takes a string argument and returns the string
// given in the argument.
textVar := demoAddIn.FunctionWithArgument('Using FunctionWithArgument to change data');
MESSAGE('Argument data is %1', textVar);
Sign In or Register to comment.