This project is read-only.
2

Closed

Add-BindingRedirect error "'object' does not contain a definition for 'References'"

description

Package Manager Console:

PM> Add-BindingRedirect -ProjectName ClassLibrary1
Add-BindingRedirect : 'object' does not contain a definition for 'References'
At line:1 char:1
Add-BindingRedirect -ProjectName ClassLibrary1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (:) [Add-BindingRedirect], RuntimeBinderException
FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.AddBindingRedirectCommand

Conditions:

This only happens, when the project updated has reference to Database project. Example solution is in attachment. You must have "Microsoft SQL Server Data Tools" installed to try this. http://go.microsoft.com/fwlink/?LinkID=274984
I need reference to database project because I need to specify build order - output of the database project (dacpac file) is used by build of the library.

file attachments

Closed Jun 7, 2013 at 12:31 AM by deepakverma
verified it doesn;t show an error

comments

dotnetjunky wrote Apr 8, 2013 at 11:03 PM

NuGet doesn't support Database project right now, but we'll accept a pull request to fix this.

veselkamartin wrote Apr 9, 2013 at 9:22 AM

This error is not happening in database project. This error is happening when adding binding redirects to standard class library project. This project only references database project.

veselkamartin wrote Apr 9, 2013 at 4:15 PM

Some more info - this error is happening in method NuGet.VisualStudio.GetLocalProjectAssemblies(Project project, IFileSystemProvider projectFileSystemProvider) on line 738:
References references = project.Object.References;
This is happening when NuGet is recursively searching for project references. Database projects do not have references and therefore NuGet fails with exception. This can be fixed by checking that "project.Object" has property "References" and if not, continue without adding references from this project.
I'm not able to debug into this method, but I suggest using code as:
if(((IDictionary<String, object>)project.Object).ContainsKey("References")) {
    References references = project.Object.References;
    foreach (Reference reference in references)
    {
        //...
    }
}
OR simply catch and ignore this error
try
{
    References references = project.Object.References;
    foreach (Reference reference in references)
    {
        //...
    }
}
catch (RuntimeBinderException)
{
    //References property doesn't exist, project does not have references
} 
Stack trace for the exception:
InnerException : Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'References'
                at CallSite.Target(Closure , CallSite , Object )
                at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
                at CallSite.Target(Closure , CallSite , Object )
                at NuGet.VisualStudio.ProjectExtensions.GetLocalProjectAssemblies(Project project, IFileSystemProvider projectFileSystemPro
             vider)
                at NuGet.VisualStudio.ProjectExtensions.GetAssemblyClosure(Project project, IFileSystemProvider projectFileSystemProvider, 
             IDictionary`2 visitedProjects)
                at NuGet.VisualStudio.ProjectExtensions.<>c__DisplayClass19.<GetAssemblyClosure>b__18(Project p)
                at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
                at NuGet.CollectionExtensions.AddRange[T](ICollection`1 collection, IEnumerable`1 items)
                at NuGet.VisualStudio.ProjectExtensions.GetAssemblyClosure(Project project, IFileSystemProvider projectFileSystemProvider, 
             IDictionary`2 visitedProjects)
                at NuGet.VisualStudio.RuntimeHelpers.<>c__DisplayClass2.<AddBindingRedirects>b__0()
                at Microsoft.VisualStudio.Shell.InvokableFunction`1.InvokeMethod()
                at Microsoft.VisualStudio.Shell.InvokableBase.Invoke()
TargetSite     : Void InvokeOnUIThread(Microsoft.VisualStudio.Shell.InvokableBase)
StackTrace     :    at Microsoft.VisualStudio.Shell.ThreadHelper.InvokeOnUIThread(InvokableBase invokable)
                at Microsoft.VisualStudio.Shell.ThreadHelper.Invoke[TResult](Func`1 method)
                at NuGet.VisualStudio.RuntimeHelpers.AddBindingRedirects(Project project, IFileSystemProvider fileSystemProvider, AppDomain
              domain, IDictionary`2 projectAssembliesCache, Boolean checkProjectType)
                at NuGet.PowerShell.Commands.AddBindingRedirectCommand.ProcessRecordCore()
                at NuGet.PowerShell.Commands.NuGetBaseCommand.ProcessRecord()
HelpLink       : 
Source         : Microsoft.VisualStudio.Shell.10.0
HResult        : -2146233088

dotnetjunky wrote Apr 9, 2013 at 6:14 PM

Do you want to send out a pull request?

dotnetjunky wrote Apr 15, 2013 at 5:54 PM

Fixed in changeset 393a61199ea92e7e155dfe12f9832f5c9a6498ca